提交 d9afa860 authored 作者: noelgrandin's avatar noelgrandin

don't leak a connection

上级 3c6c9b1c
......@@ -51,12 +51,12 @@ public class InitDatabaseFromJar {
*/
void initDb() throws Exception {
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:mem:test");
InputStream in = getClass().getResourceAsStream("script.sql");
if (in == null) {
System.out.println("Please add the file script.sql to the classpath, package "
+ getClass().getPackage().getName());
} else {
Connection conn = DriverManager.getConnection("jdbc:h2:mem:test");
RunScript.execute(conn, new InputStreamReader(in));
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("SELECT * FROM TEST");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论