MYSQL Insert查询不在JAVA中更新表中的数据
我正在开发一个JAVA程序,需要从文本文件更新数据库。我已成功插入和更新数据。但是我在这里面临一个问题,这个方法。查询运行时没有错误,并给出响应。但是数据库表没有更新MYSQL Insert查询不在JAVA中更新表中的数据,java,mysql,Java,Mysql,我正在开发一个JAVA程序,需要从文本文件更新数据库。我已成功插入和更新数据。但是我在这里面临一个问题,这个方法。查询运行时没有错误,并给出响应。但是数据库表没有更新 private void filteData() { System.out.println("filteData"); Statement statementAtenLogInsert = null; Statement statementqCheck = null;
private void filteData() {
System.out.println("filteData");
Statement statementAtenLogInsert = null;
Statement statementqCheck = null;
Statement statementUpdateProLog = null;
Statement statementEnterError = null;
ResultSet rs = null;
int rcount;
//Update successfull attendance_test
String attenLogInsertSuccess = "INSERT INTO attendance_log (user_id, check_in, check_out) SELECT user_id, check_in, check_out FROM process_log WHERE flag = 'S'";
try {
statementAtenLogInsert = connection.createStatement();
statementAtenLogInsert.execute(attenLogInsertSuccess);
int qSuccess = statementAtenLogInsert.executeUpdate(attenLogInsertSuccess);
System.out.println("qSuccess " + qSuccess);
if(qSuccess > 0){
String deleteProcessLog = "DELETE FROM process_log WHERE flag = 'S'";
statementAtenLogInsert.execute(deleteProcessLog);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
这里的attenLogInsertSuccess和deleteProcessLog查询不起作用。表示数据库表端没有发生任何事情。但是成功给了我价值。这意味着将触发attenLogInsertSuccess。但是mysql端什么也没发生。您需要关闭连接才能刷新对数据库的更改 尝试添加
connection.close()
在管道中的某个位置,通常在finally块中关闭连接以确保它始终处于关闭状态,但似乎您已在其他位置定义了连接,可能是为了在调用函数中重复使用
您还需要在关闭连接之前关闭语句。有关模式,请参阅。您需要关闭连接以刷新对数据库的更改 尝试添加
connection.close()
在管道中的某个位置,通常在finally块中关闭连接以确保它始终处于关闭状态,但似乎您已在其他位置定义了连接,可能是为了在调用函数中重复使用
您还需要在关闭连接之前关闭语句。请参阅以了解模式。这可以是@gwnp的注释,至少可以显示如何关闭连接:)这可以是@gwnp的注释,至少可以显示如何关闭连接:)