提交 c23bb0ed authored 作者: Noel Grandin's avatar Noel Grandin

close a couple of resource leaks

上级 c1087334
......@@ -11,7 +11,6 @@ import java.io.LineNumberReader;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.h2.test.TestBase;
import org.h2.util.ScriptReader;
......@@ -43,34 +42,34 @@ public class TestScriptSimple extends TestBase {
InputStream is = getClass().getClassLoader().getResourceAsStream(inFile);
LineNumberReader lineReader = new LineNumberReader(
new InputStreamReader(is, "Cp1252"));
ScriptReader reader = new ScriptReader(lineReader);
while (true) {
String sql = reader.readStatement();
if (sql == null) {
break;
}
sql = sql.trim();
try {
if ("@reconnect".equals(sql.toLowerCase())) {
reconnect();
} else if (sql.length() == 0) {
// ignore
} else if (sql.toLowerCase().startsWith("select")) {
ResultSet rs = conn.createStatement().executeQuery(sql);
while (rs.next()) {
String expected = reader.readStatement().trim();
String got = "> " + rs.getString(1);
assertEquals(sql, expected, got);
try (ScriptReader reader = new ScriptReader(lineReader)) {
while (true) {
String sql = reader.readStatement();
if (sql == null) {
break;
}
sql = sql.trim();
try {
if ("@reconnect".equals(sql.toLowerCase())) {
reconnect();
} else if (sql.length() == 0) {
// ignore
} else if (sql.toLowerCase().startsWith("select")) {
ResultSet rs = conn.createStatement().executeQuery(sql);
while (rs.next()) {
String expected = reader.readStatement().trim();
String got = "> " + rs.getString(1);
assertEquals(sql, expected, got);
}
} else {
conn.createStatement().execute(sql);
}
} else {
conn.createStatement().execute(sql);
} catch (SQLException e) {
System.out.println(sql);
throw e;
}
} catch (SQLException e) {
System.out.println(sql);
throw e;
}
}
is.close();
conn.close();
deleteDb("scriptSimple");
}
......
......@@ -46,16 +46,17 @@ public class TestScriptReader extends TestBase {
}
String s = buff.toString();
StringReader reader = new StringReader(s);
ScriptReader source = new ScriptReader(reader);
for (int j = 0; j < l; j++) {
String e = source.readStatement();
String c = sql[j];
if (c.length() == 0 && j == l - 1) {
c = null;
try (ScriptReader source = new ScriptReader(reader)) {
for (int j = 0; j < l; j++) {
String e = source.readStatement();
String c = sql[j];
if (c.length() == 0 && j == l - 1) {
c = null;
}
assertEquals(c, e);
}
assertEquals(c, e);
assertEquals(null, source.readStatement());
}
assertEquals(null, source.readStatement());
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论