private static void search(Connection conn) throws SQLException {
try ( PreparedStatement stat = conn.prepareStatement("select * from town where zip=9999")) {
ResultSet res = stat.executeQuery();
while (res.next()) {
System.out.println(res.getString("zip")+" "+res.getString("name"));
}
}
}
private static void bewerk(Connection conn) throws SQLException {
try ( PreparedStatement stat = conn.prepareStatement("INSERT into town VALUEs (9999,'zzzZZZzzz')")) {
int res = stat.executeUpdate();
System.out.println(res);
}
}
public static void main(String[] args) {
try {
Class.forName(JDBC_DRIVER);
try (Connection conn = DriverManager.getConnection(JDBC_URL)) {
bewerk(conn);
search(conn);
} catch (SQLException e) {
System.err.println("Database error: " + e);
}
} catch (ClassNotFoundException e) {
System.err.println("Database driver niet gevonden: " + e);
}
}
为什么代码不更新我的数据库? 我执行了这段代码,用sqliteBrowser(一个打开DB的程序)检查了它,但是我找不到我的新值。 (automaticCommit设置为True)