我正在使用AWS RDS(特别是mysql),我正在使用SQL Workbench/J作为GUI工具。用Java编写的,在这里我的服务器端代码是我的代码:Java mysql AWS执行成功,然后选择不返回新值
插入代码:
try {
Statement myStatement = insertConnectionObject.createStatement();
myStatement.executeUpdate("INSERT INTO friends VALUES('buddy', '15', '123');");
myStatement.close();
} catch(Exception ex) {
// code for handling exceptions
} finally {
myStatement.close();
insertConnectionObject.close();
}
在那之后,我把从同一个表中选择代码:
try {
Statement myStatement = selectConnectionObject.createStatement();
ResultSet returnedFriends = myStatement.executeQuery("SELECT * FROM friends;");
//unfortunately, the returnedFriends will not return the new inserted value 'buddy'
} catch(Exception ex) {
// code for handling exceptions
} finally {
myStatement.close();
insertConnectionObject.
不幸的是,返回的朋友不会返回新的插入值'朋友'。
如果我将点击SQL Workbench/J GUI工具中的'提交任何待处理的数据库更改'按钮,然后运行select语句,新值'buddy'将返回。
我到现在为止试过了什么?
- 对insert和select使用相同的连接对象。
- 在insert命令之后和每个select命令之后,打开和关闭连接。
- 禁用自动提交并尝试手动提交。
- 通过代码插入,然后直接从数据库中选择。
是的我试过第一个建议没有运气,连接已经设置为自动提交。 select语句由我在所描述的流程中忽略的代码的不同部分调用,只是为了使其更清晰。 – 2014-11-03 09:46:29