Hello...

I'm trying to use H2 to perform unit testing of some methods that act
upon a database. This is a maven project, so I have created an H2
database with sample data and put that in src/test/resources/
testdb.h2.db

When my unit test class runs, it copies testdb.h2.db to the system
temp dir, and uses the copied file to create an instance of DBCP's
BasicDatasource like this:

      File file = File.createTempFile(dbname, ".h2.db");
 
FileUtils.copyURLToFile(ClassLoader.getSystemClassLoader().getResource(dbname
+ ".h2.db"), file);

      BasicDataSource ds = new BasicDataSource();
      ds.setDriverClassName("org.h2.Driver");
      ds.setUsername("sa");
      ds.setPassword("");
      ds.setUrl("jdbc:h2:file:" + file.getAbsolutePath());

The problem is that when the code tries to access any of the tables
with that datasource, they are not found:

org.springframework.jdbc.BadSqlGrammarException:
PreparedStatementCallback; bad SQL grammar [SELECT VariationTypeUID
FROM VariationType WHERE VariationType = ?]; nested exception is
org.h2.jdbc.JdbcSQLException: Table "VARIATIONTYPE" not found; SQL
statement:
SELECT VariationTypeUID FROM VariationType WHERE VariationType = ?
[42102-136]

If I connect directly to the copied file (eg: jdbc:h2:file:/var/
folders/py/pyzGIi9nEGWr5A84ePz24++++TI/-Tmp-/
testdb435327911103145885.h2.db) I can see all the tables and run the
queries without any problem. I'm using the "sa" username in both
cases.

Anyone have any ideas why this might be?

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Reply via email to