Reputation: 18809
I am trying to create a H2 DB to a file. a small module first runs that creates the file and the schema and populates it with data. While doing this this the H2 jdbc url used:
jdbc:h2:file:c:\\Yogesh\\TestH2Db;MODE=Oracle;INIT=CREATE SCHEMA IF NOT EXISTS TEST\\;SET SCHEMA TEST\\;
A DDL script for the schema is run and then on this I am loading up some data using RunScript class. After the loadup this module stop (The JVM dies/is no longer running).
A second module, tries to use this pre-created data based to run some tests. To connect to this DB i am trying to use this url:
jdbc:h2:file:c:\\Yogesh\\TestH2Db;IFEXISTS=TRUE;MODE=Oracle;INIT=CREATE SCHEMA IF NOT EXISTS TEST\\;SET SCHEMA TEST\\;
Basically the same url but with IFEXISTS=TRUE added. A JdbcConnectionPool is create based on this URL.
protected JdbcConnectionPool initConnectionPool(String user, String pwd,
int maxConn, String jdbcUrl) {
System.setProperty("h2_jdbc_url", jdbcUrl);
JdbcConnectionPool connpool = JdbcConnectionPool.create(
jdbcUrl, user, pwd);
connpool.setMaxConnections(maxConn);
return connpool;
and when the rest of the module does a getConnection on the above created JDBC Connection pool, it fails and seems to be creating the same objects that I had created in the Init module again.
I have tried it without the INIT=CREATE SCHEMA IF NOT EXISTS TEST\;SET SCHEMA TEST\; to no avail
Edit: To add the stack Trace
org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement
[Have a create view statement here that fails cant give out the SQL statement,
however note that this SQL statement ran fine
when i used RunScript tool to init the DB schema;
What i don't understand is while doing get connection the
connection Pool why are objects
being inited again, the Schema creation script is not part of the
INIT part of JDBC Url]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
at org.h2.message.DbException.get(DbException.java:169)
at org.h2.message.DbException.getSyntaxError(DbException.java:194)
at org.h2.command.Parser.getSyntaxError(Parser.java:491)
at org.h2.command.Parser.read(Parser.java:2798)
at org.h2.command.Parser.readIfMore(Parser.java:809)
at org.h2.command.Parser.parseColumnList(Parser.java:778)
at org.h2.command.Parser.parseCreateView(Parser.java:4281)
at org.h2.command.Parser.parseCreate(Parser.java:3749)
at org.h2.command.Parser.parsePrepared(Parser.java:324)
at org.h2.command.Parser.parse(Parser.java:279)
at org.h2.command.Parser.parse(Parser.java:255)
at org.h2.command.Parser.prepare(Parser.java:201)
at org.h2.engine.Session.prepare(Session.java:388)
at org.h2.engine.Session.prepare(Session.java:375)
at org.h2.engine.MetaRecord.execute(MetaRecord.java:56)
at org.h2.engine.Database.open(Database.java:632)
at org.h2.engine.Database.openDatabase(Database.java:222)
at org.h2.engine.Database.<init>(Database.java:217)
at org.h2.engine.Engine.openSession(Engine.java:56)
at org.h2.engine.Engine.openSession(Engine.java:159)
at org.h2.engine.Engine.createSessionAndValidate(Engine.java:138)
at org.h2.engine.Engine.createSession(Engine.java:121)
at org.h2.engine.Engine.createSession(Engine.java:28)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:305)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:109)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:93)
at org.h2.Driver.connect(Driver.java:72)
at org.h2.jdbcx.JdbcDataSource.getJdbcConnection(JdbcDataSource.java:181)
at org.h2.jdbcx.JdbcDataSource.getXAConnection(JdbcDataSource.java:315)
at org.h2.jdbcx.JdbcDataSource.getPooledConnection(JdbcDataSource.java:341)
at org.h2.jdbcx.JdbcConnectionPool.getConnectionNow(JdbcConnectionPool.java:226)
at org.h2.jdbcx.JdbcConnectionPool.getConnection(JdbcConnectionPool.java:199)
at junit.db.utils.InitH2DB.getConnection(InitH2DB.java:45)
at test.DBLoader.DBLoader.main(DBLoader.java:21)
Upvotes: 0
Views: 3627
Reputation: 18809
The Error was because of an incorrect script used to create teh H2 schema. See comments below the question for more details.
Upvotes: 1