Boostrapping H2 database with schema / data from SQL script
It's really easy to bootstrap H2 with schema and data stored in an SQL script on classpath. Here is an example with DBUtils.
import org.apache.commons.dbutils.QueryRunner;
import org.h2.jdbcx.JdbcConnectionPool;
// ....
JdbcConnectionPool connectionPool = JdbcConnectionPool.create("jdbc:h2:mem:testing", "user", "password");
QueryRunner runner = new QueryRunner(connectionPool);
runner.update("RUNSCRIPT FROM 'classpath:eventstore/jdbc/h2-bootstrap.sql' CHARSET 'utf-8'");
Pretty convenient for integration tests!
Written by Kim A. Betti
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Sql
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#