Not able to access the tables from H2 database using Java - h2

I created a script for Database Testing using H2 database. I am facing issue, not able to read the tables in database. It throwing the message "Table not Found" and below code. But it is able to connect the database.
Configuration : h2-3.3.jar and h2.jar for Database Engine
Class.forName("org.h2.Driver");
Connection con=DriverManager.getConnection("jdbc:h2:file:C:\\keymanager\\etc\\H2/kms;CIPHER=AES","km_user","87654321 12345678");
System.out.println(con.getCatalog());
Statement statement = con.createStatement();
ResultSet resultSet1 = con.createStatement().executeQuery("SELECT * FROM KM_AUDITLOGS");
while(resultSet1.next()){
System.out.println("CREATEDATE:" +resultSet1.getString("USERIP"));
}
After executing the Script error message has been displayed
"org.h2.jdbc.JdbcSQLException: Table KM_AUDITLOGS not found; SQL statement:
SELECT * FROM KM_AUDITLOGS [42102-73]"
Any one can help me?

When using the latest version of H2, it is working (according to the last comment).

Related

Spark JDBC cannot find temporary tables

We created a temporary table (in memory) through spark.
When we sftp to the server and use beeline, we can query on the this temporary table like "select * from Table1" without issue.
However, when we use GUI tool with corresponding driver on local machine (the connection string is "jdbc:spark://servername:port/default" ), we have trouble. We can see the temporary table Table1 by using "show tables;" in the GUI tool. However, when we try to use "select * from Table1" in the tool, It shows an error "[Simba]JSQLEngine The table "Table1" could not be found., SQL state: HY000, Query: select * from Table1. [SQL State=HY000, DB Errorcode=500051]". Note that we are using the trial version of the Simba JDBC driver for testing.
Also, I tried hive-jdbc driver from cloudra using connection string "jdbc:hive2://servername:port/default". It is the same issue. Please help. Thanks a lot.
It turns out that some of the drivers requires a "limit" clause after the select. Once I add that, it retrieved data.

Error running SQL queries with Liquibase

I'm using Liquibase to create tables in DB2. I have a simple example changelog that tries to drop and then create a table.
The SQL statements work fine via my DbVisualizer tool (which uses the same JDBC driver as Liquibase) and also works fine when submitted via the db2 command line tool.
Here's the Liquibase input file:
--changeset dank:1 runAlways=true failOnError:false
DROP TABLE AAA_SCHEMA.FOO
--changeset dank:2 runAlways=true
CREATE TABLE AAA_SCHEMA.FOO ( MYID INTEGER NOT NULL )
Here's the error message I get:
Caused by: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error:
SQLCODE=-104, SQLSTATE=42601, SQLERRMC=DROP TABLE AAA_SCHEMA.FOO;
;, DRIVER=4.18.60
The IBM error code -104 is about syntax problems. Based on looking at the error message my guess is that it has something to do with the end of line character ";". But I've tried the query with and without the semi-colon. The semi-colon is accepted by IBM's own db2 too, so it seems like a valid choice.
Any help in figuring out the cause of this error is much appreciated.
The problem was me forgetting to start my native sql file with this required line:
--liquibase formatted sql
Doh!

Spring embedded DB schema not found issue

I am using embedded HSQLDB in my JUnits. It is throwing
SQL state [3F000]; error code [-4850]; invalid schema name:info
when it executes query following query
select db.id, db.name,info.desc from user_db db,user_info info where db.user_id = info.user_id and info.active = 'Y' and db.dept = info.dept(+)
the above query runs fine in oracle but not in embedded HSQLDB
please let me know what is wrong in this.

Max open cursors exceeded - Oracle 11g | ibatis 2.3.4 | spring 3.0.3

We have recently migrated from Sybase to Oracle 11g database. Our application uses spring 3.0.3 along with IBATIS 2.3.4 to interact with database.
Recently, we have started facing ORA-01000 Maximum open cursors exceeded exception.
We talked to our DBA and he confirmed that for each row insertion we are occupying one cursor which is not correct. The cursor size is 300 as set by the DBA.
Can you please suggest how do we handle this through ibatis configuration or Java code?
We've never faced this issue with Sybase.
The current code structure in our DAO class:
try{
sqlMapClient.startTransaction();
sqlMapClient.startBatch();
for(...){
sqlMapClient.insert(<in table 1>);
sqlMapClient.insert(<in table 2>);
}
sqlMapClient.executeBatchDetailed();
sqlMapClient.commitTransaction();
}
catch(..){
}
finally{
sqlMapClient.endTransaction();
}
Note: We cannot perform intermediate commit as the operation needs to be all or none.
You can increase cursor number using with following statement. Only DBA user can execute the following statement. This problem will occur whenever if you have performance issue with your pl/sql coding. Please try to tune procedure / sql.
ALTER SYSTEM SET open_cursors = 400 SCOPE=BOTH;

multiple tables creation at runtime

i need to create a standalone database app using java and HSQL, the constructor of the app creates the database and 2 tables.I wrote the following:
Connection connection =DriverManager.getConnection(
jdbc:hsqldb:file:D:\\prod \\prod,"SA","");
Statement statement1=connection.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
statement1.executeQuery(query1);
statement1.close();
Statement statement2=connection.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
statement2.executeQuery(query2);
statement2.close();
connection.close();
aftre running the application, only the first statement has been executed and one table has been created without any SQL exceptions. any help.............best ergards
You shouldn't use executeQuery(text) for CREATE TABLE and other data definition statements.
Use executeUpdate(text) instead.

Resources