I'm using the Impala JDBC driver (or I guess it's actually the Hive Server 2 JDBC driver). I have a view created in another database -- let's call it "store55".
Let's say my view is defined as follows:
CREATE VIEW good_customers AS
SELECT * from customers WHERE good = true;
When I try to query this view using JDBC as follow:
SELECT * FROM store55.good_customers LIMIT 10
I get an error such as:
java.sql.SQLException: AnalysisException: Table does not exist: default.customers
Ideally, I'd like to specify the database name somewhere in the JDBC URL or as a parameter but when I try to use this JDBC url, I still get the same error:
jdbc:hive2://<host>:<port>/store55;auth=noSasl
Doe the Hive2 JDBC driver just ignore the database part of the URL and assume all queries are executed against the default database?
The only way I was able to have the queries return is to change the view definition itself to include the database name:
CREATE VIEW good_customers AS
SELECT * from store55.customers WHERE good = true;
However, I'd like to keep the view definition free of database names.
Thanks!
You might want to specify in JDBC the "use database xxxxx;" statement.
Also, if you are already using the database try "invalidate metadata" statement.
The URL is jdbc:hive2://:/store55;auth=noSasl correct
Can you run few diagnostics such as:
SHOW TABLES - to ensure that the view is created in store55
Are you using the USE DATABASE command in the DDL's
Related
I'm getting the below error on Tableau Desktop when using the custom query, I'm successfully able to connect and see contents from the table when directly drag the table to query builder section on Tableau Desktop.
Datasource used: AWS Athena
Driver version: AthenaJDBC42_2.0.2
Tableau Desktop version: 10.4
com.tableausoftware.jdbc.TableauJDBCException: Error reading metadata for executed query: SELECT * FROM ( select * from tablename ) "TableauSQL" LIMIT 0 [Simba][AthenaJDBC](100071) An error has been thrown from the AWS Athena client. Only one sql statement is allowed. Got: SELECT * FROM ( select * from tablename ;) "TableauSQL" LIMIT 0
There was a Java error.
Unable to connect to the server "Athena.us-east-1.amazonaws.com". Check that the server is running and that you have access privileges to the requested database.
Try removing the ; from the subquery - That always throws errors for me
I was having the same issue.
To provide some clarity to the above - the outer query is being added by Tableau. Here is my simple query and the error being returned by Tableau.
I was able to resolve by changing my query to refer to my table in the form "database"."table" and remove the closing ;
This custom query then worked for me:
From the Unity JDBC download page:
If the SQL query requires joins or functions not supported by MongoDB, then the query is promoted to UnityJDBC (trial version). The UnityJDBC trial version has no expiration date and is fully functioning except that it is limited to returning up to 100 results.
However, when I try to join two tables using any syntax like
SELECT * from a, b WHERE a.id = b.id
SELECT * from a INNER JOIN b ON a.id = b.id
SELECT * from a INNER JOIN b USING (id)
Results in the following:
Exception: java.sql.SQLException: ERROR: No schema defined. The default schema location is _schema in the current database. You need write permission to create this collection. Otherwise, use the schema parameter to set a file location (e.g. schema=mongo.xml) to store the schema. See connection parameters at http://www.unityjdbc.com/mongojdbc/ for more details.
java.sql.SQLException: ERROR: No schema defined. The default schema location is _schema in the current database. You need write permission to create this collection. Otherwise, use the schema parameter to set a file location (e.g. schema=mongo.xml) to store the schema. See connection parameters at http://www.unityjdbc.com/mongojdbc/ for more details.
at mongodb.conn.ServerConnection.processMongoWithUnity(Unknown Source)
at mongodb.conn.ServerConnection.executeQuery(Unknown Source)
at mongodb.jdbc.MongoStatement.executeQuery(Unknown Source)
at mongodb.ExampleMongoJDBC.doQuery(ExampleMongoJDBC.java:222)
at mongodb.ExampleMongoJDBC.main(ExampleMongoJDBC.java:66)
Ok, so I took a look in the readme and found it mentioning the code/test/dspec/ folder with some files related to schemas. I opened a few up, they are highly detailed xml files of all the collections mapping them to relational data types.
Do I have to write one of these out, or is there a way to auto generate it?
I received a (fast) response from the Unity team.
The MongoDB JDBC driver has two modes. For single collection queries, it does not build a schema. For queries involving joins or expressions it builds a schema and by default stores it in the _schema collection in the current Mongo database. If you do not have permission to write to the database, an error is thrown.
As mentioned in the error, you can set the schema parameter to be a local file name (such as mongo.xml) and it will store it on your computer rather than in the Mongo database. You could also use an account that has write permissions.
To make this work, add schema=mongo.xml to your connection URL like this:
jdbc:mongo://localhost/dbname?schema=mongo.xml?rebuildschema=true
After this is done the first time, you can remove the rebuildschema=true or it will rebuild it every time.
The only thing I'm confused about is that I'm using a database which doesn't require authentication. I even made a user with write permissions, connected to him, and still received the above error.
--EDIT
I realized that you could also just do jdbc:mongo://localhost/dbname?rebuildschema=true. If the schema hasn't been created, then the previous error will be thrown.
It's my first try to use EJB3.1 entities with a JBoss AS7.1.1 server. I figured out that the HSQLDB is no longer included in the version 7 of JBoss. First I added the hsqldb.jar through the Administration Console --> Deployments --> Manage Deployments. After that I added a new Data Source through Profil --> Connector -> Datasources
My first example code works fine:
[...]
InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup("java:/DefaultDS");
con = ds.getConnection();
stmt = con.createStatement();
stmt.execute("drop table timers;");
stmt.execute("Create table timers(id char(10));");
stmt.execute("INSERT INTO timers (id) VALUES (20)");
stmt.execute("INSERT INTO timers (id) VALUES (21)");
ResultSet number = stmt.executeQuery("select * from timers");
[...]
My question is how I can manage (=create, drop and update new tables) the DB which is created in the folder jobss\standalone\data\hypersonic. At the moment I have no "overview" which tables are created, the structure of them and the data.
Does someone have a tip or a tutorial for me which deal with the problem? Thank you.
In my case it was easier as I thought at the beginning. I needed to manage the DB which is stored in the AS 7.1.x Server. Because of the missing JMX-Console I wasn't able to get access to that DB over the administration. I've added the Datasource and the Manage Deployments as described in the first post.
To manage such a DB you can use the 'HSQLDB Database Manager', select 'HSQL Database Engine Standalone' as the type and 'jdbc:hsqldb:file:«MY_PATH_TO_DB_FOLDER_IN_JBOSS»' for the URL. Now I can manage the DB outside the server and EJB environment.
Thanks you fredt for your help and your inspirations.
You always query INFORMATION_SCHEMA tables to find out which tables already exist. Once you know a table exists, you can execute a query that you know does not take a long time, in order to find out about the state of the data.
For example, the first query will show you if there is a 'TIMERS' table, and the second query will show if there is any data in the table:
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'TIMERS'
SELECT * FROM TIMERS LIMIT 1
Try always to define a primary key on each table in order to speed up queries.
To access a database embedded in an app server, you should add the org.hsqldb.server.Servlet class as a servlet then connect to the app server using a database management tool and a URL such as jdbc:hsqldb:http:<your servlet url here>
How do I query the database name in Oracle SQL Developer? I have tried the following and they all fail:
SELECT DB_NAME();
SELECT DATABASE();
Why do these basic MySQL queries fail in SQL Developer? Even this one fails too:
show tables;
EDIT: I can connect to the database and run queries such as:
select * from table_name_here;
EDIT 2: The database type is Oracle, this is why MySQL queries are failing. I thought it was related to the database client not the database itself. I was wrong. I'll leave the question as is for other as lost as I was.
Once I realized I was running an Oracle database, not MySQL, I found the answer
select * from v$database;
or
select ora_database_name from dual;
Try both. Credit and source goes to: http://www.perlmonks.org/?node_id=520376.
try this:
select * from global_name;
You can use the following command to know just the name of the database without the extra columns shown.
select name from v$database;
If you need any other information about the db then first know which are the columns names available using
describe v$database;
and select the columns that you want to see;
I know this is an old thread but you can also get some useful info from the V$INSTANCE view as well. the V$DATABASE displays info from the control file, the V$INSTANCE view displays state of the current instance.
Edit: Whoops, didn't check your question tags before answering.
Check that you can actually connect to DB (have the driver placed? tested the conn when creating it?).
If so, try runnung those queries with F5
To see database name,
startup;
then type
show parameter db_name;
DESCRIBE DATABASE NAME; you need to specify the name of the database and the results will include the data type of each attribute.
In postgresql a query in the querylog gets something like this:
2009-02-05 00:12:27 CET LOG: duration: 3781.634 ms execute <unnamed>: SELECT QUERY ....
Is there a possibility to put something more usable into the "< unnamed >" placed like the url the query was requested from?
Are there any other possibilities to track the origin of a query in postgresql using jdbc from java?
Thanks
Short answer is "no"
The name can be set when preparing the statement, using the PREPARE command, but that requires rewriting all your SQL. There is no option to simply add a name parameter to your JDBC methods.
The JDBC driver makes use of both named and unnamed prepared statements. It will give them a name when it wishes to reuse them, which it will deem appropriate if the same PreparedStatement object is executed 5 times (though that is configurable through setting the prepareThreshold).
Documentation is here
More info can also be found by searching the PostgreSQL JDBC mailling list