我的web应用程序中有一个网格,其中数据直接使用jQuery API从web服务中获取。要求是
为了实现这一点,我使用了JDBC并将它们保存在一个堆栈中,这个堆栈允许撤消操作。我在update语句之前设置一个保存点,在撤销时我希望它回滚到最后一个保存点并提交很简单。
我首先在桌面应用程序上测试了它,它运行得很好,但是在基于Web的应用程序中,它不起作用。
数据库连接类
private static Map<String, Connection> userConnections;
public static Connection getConnection(configsJson) {
... //getdata from json
if (userConnections == null) {
userConnections = new HashMap<>();
} else {
userConnection = userConnections.get(userKey);
}
if (userConnection == null) {
userConnection = DriverManager.getConnection("jdbc:oracle:thin:@" + sourceIP + ":" + sourcePort + ":" + sourceInstance, sourceUser, sourcePass);
userConnection.setAutoCommit(false);
userConnections.put(userKey, userConnection);
}
return userConnection;
}我的更新功能
private static Map<String, Stack<Savepoint>> userSavePoints = new HashMap<>();
@ResponseBody
@RequestMapping(value = "/webservice/updateRecord", method = RequestMethod.POST)
public int updateRecord(HttpServletRequest request, @RequestParam String configs) throws SQLException, JSONException, ParseException {
Connection con = DBService.getConnection(configJson);
...
userSavePoints.get(userKey).push(con.setSavepoint());
return statement.executeUpdate(sql);
}如果这里没有保存点语句,那么在更新之后,我可以在我的网页上看到更改的记录,这些记录还没有保存在数据库中,因为自动提交设置为false。问题在于这个保存点语句的网格没有显示已更改的记录。在我看来,似乎这些记录还没有更新,或者它们会自动回滚到这个保存点。
我的逻辑有什么问题吗?或者这些保存点不适用于restful?
发布于 2019-06-13 12:36:40
有一个愚蠢的错误,我甚至没有调查,这一行是返回null,并没有继续前进。控制台也没有显示任何异常。
userSavePoints.get(userKey)
我只需要初始化它来解决我的问题。
https://stackoverflow.com/questions/56579730
复制相似问题