Spring embedded DB schema not found issue - spring

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.

Related

How to use getDate() in h2 as like sql server

I'm testing the already developed application through Junit test cases, uses SQL server in production but while executing test cases we used embedded h2 database.
And some of the SQL server specifications are not working in h2 (ex: conditional queries, getDate(), DATEPART,..........) can anyone help me how to tackle this kind issues further in my JUnit testing with h2 DB
SQL SERVER: select * from getDate() -: 2006-12-30 00:38:54.840
h2 DB : select * from getDate() -: 2006-12-30
While executing test cases that scripts are executing in h2 database and as a part of logic, I'm parsing the value from getdate() into SimpleDate format of 2006-12-30 00:38:54.840, and I'm getting parse exception that 2006-12-30 couldn't parse.
Thanks in Advance
To use getDate in H2, simply run the following query before using a query with getDate()
drop alias if exists getDate;
create alias getDate as '
java.util.Date getDate() {
return new java.util.Date();
}
';
You can use User-Defined Functions and Stored Procedures built in H2 database.

In Jmeter, JDBC Request is returning only name of column with no values for a Select query

My Environment: JMeter v3.2, Oracle 11, java 1.8
I am able to successfully establish JDBC connection to the database using JDBC Connection Configuration.
However, the JDBC Request in which i am executing a select query.
I am getting only the name of the column in result with empty value.
I've confirmed the SQL is fine by running the SQL in Oracle Developer, data is returned successfully.
My workings:
JDBC Request --> Query Type: Select Statement
select policy_code from bas_policy where policy_code='KP550 '
When I run the JDBC Request - the report in the View Results Tree Listener shows successful execution.
Response data in Debug Sampler:
JMeterVariables:
JMeterThread.last_sample_ok=true
JMeterThread.pack=org.apache.jmeter.threads.SamplePackage#15ec91
Pool1=org.apache.jmeter.protocol.jdbc.config.DataSourceElement
$DataSourceComponentImpl#cfef05
START.HMS=164422
START.MS=1496936662485
START.YMD=20170608
TESTSTART.MS=1496939556814
a_#=0
result=[]
Where 'a' is defined as the Variable name.
Response data in Debug Sampler
POLICY_CODE
Again, as with all my posts, I am grateful for all advice/help etc.
SOLVED. Have to use the VPD (virtual private database) id for the child instance in the query. the correct query is select POLICYN,STATUS from bas_policy#cloud_dbid_3.world

Cannot create PoolableConnectionFactory (ORA-00936: missing expression ): JDBC connection error in Jmeter3.0

I am running one jmeter script to read data from Database (using JDBC Request). Here I am getting following error if I am running script in Jmeter3.0.
Cannot create PoolableConnectionFactory (ORA-00936: missing expression
)
But same script is running fine with jmeter2.13.
Do I need to change any property values?
Just modify Validation query in JDBC Connection Configuration to select 1 from DUAL as per documentation:
A simple query used to determine if the database is still responding. This defaults to 'SELECT 1' which is suitable for many databases. However some may require a different query; for example Oracle requires something like 'SELECT 1 FROM DUAL'. Note this validation query is used on pool creation to validate it even if "Test While Idle" suggests query would only be used on idle connections. This is DBCP behaviour.

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!

Not able to access the tables from H2 database using Java

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).

Resources