JdbcTools { public static Connection connect(String klass, String jdbcUrl) throws SoarException { try { Class.forName(klass); } catch (ClassNotFoundException e) { throw new SoarException("Failed to load database driver class: " + e.getMessage(), e); } try { return DriverManager.getConnection(jdbcUrl); } catch (SQLException e) { throw new SoarException("Failed to connect to database '" + jdbcUrl + "': " + e.getMessage(), e); } }  static Connection connect(String klass, String jdbcUrl); static void executeSql(Connection db, InputStream is, String driverFilter); static void executeSqlBatch(Connection db, InputStream is, String driverFilter); static long insertAndGetRowId(PreparedStatement s); static boolean queryHasResults(PreparedStatement s); static boolean tableExists(Connection db, String table); static void printResultSet(ResultSet rs, Writer out);  }
@Test public void testCanCreateAndConnectToInMemorySqlLiteDatabase() throws Exception { final Connection conn = JdbcTools.connect("org.sqlite.JDBC", "jdbc:sqlite::memory:"); try { Statement stat = conn.createStatement(); stat.executeUpdate("drop table if exists people;"); stat.executeUpdate("create table people (name, occupation);"); PreparedStatement prep = conn.prepareStatement("insert into people values (?, ?);"); final String[][] entries = new String[][] { new String[] {"Gandhi", "politics" }, new String[] {"Turing", "computers" }, new String[] { "Wittgenstein", "smartypants" } }; for(String[] entry : entries) { prep.setString(1, entry[0]); prep.setString(2, entry[1]); prep.addBatch(); } conn.setAutoCommit(false); prep.executeBatch(); conn.setAutoCommit(true); final ResultSet rs = stat.executeQuery("select * from people;"); int index = 0; while (rs.next()) { assertEquals(entries[index][0], rs.getString("name")); assertEquals(entries[index][1], rs.getString("occupation")); index++; } rs.close(); } finally { conn.close(); } }