描述:工作台中的自动提交值已设置为0(零),然后我将记录插入到表中,并通过jdbc在Java中成功提交事务。我在命令行中执行select查询,刚刚插入的记录已经成功获取,但是在workbech中执行相同的查询脚本,无法获取刚才插入的记录。只有在工作台中执行commit命令之后,才能查询记录。
如何重复:
建议修复:工作台应该读取提交的记录,而不是再次执行提交命令来通过jdbc显示已经提交的记录。
下面是相同的jdbc代码
int recordInserted = 0;
PreparedStatement prepStmt = null;
try {
conn = new DatabaseConnection().getSQLConnection();
if (conn != null) {
String sql = "INSERT INTO customerinfo (CustID, Customer_Name, Customer_License) VALUES (?, ?, ?)";
prepStmt = conn.prepareStatement(sql);
prepStmt.setString(1, registerRecords.getCustomerID());
prepStmt.setString(2, registerRecords.getCustomerName());
prepStmt.setString(3, registerRecords.getCustomerLic());
recordInserted = prepStmt.executeUpdate();
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
conn.close();
prepStmt.close();
conn = null;
prepStmt=null;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}发布于 2016-11-02 08:02:48
这意味着您必须手动提交来自Java的事务。
但是您从来没有真正从Java提交。你应该这么做:
conn.commit();完整代码:
if (conn != null) {
String sql = "INSERT INTO customerinfo (CustID, Customer_Name, Customer_License) VALUES (?, ?, ?)";
prepStmt = conn.prepareStatement(sql);
prepStmt.setString(1, registerRecords.getCustomerID());
prepStmt.setString(2, registerRecords.getCustomerName());
prepStmt.setString(3, registerRecords.getCustomerLic());
recordInserted = prepStmt.executeUpdate();
conn.commit();
}https://stackoverflow.com/questions/40374473
复制相似问题