JDBC 不返回结果集
我们正在将其从 WAS 5 迁移到 WAS 7,但我们很困惑为什么这现在会导致问题。 executeQuery() 行抛出一个 SQLException,表示它没有返回 ResultSet。有谁知道 WAS 的生命周期中发生了什么变化,使得这种方法不再起作用?这是 JDBC 升级还是 JRE 的事情?我用谷歌搜索了一下,但我真的不确定我应该搜索什么,所以我的搜索没有结果。
query = "insert into ST_Users ";
query += "(ST_U_First_Name, ST_U_Middle_Name,
ST_U_Last_Name, ST_U_Facility_Name,
ST_U_Last_Trans_ID, ST_U_Last_Trans_Time) ";
query += "values (?,?,?,?,?,?)";
query += ";select SCOPE_IDENTITY() as UserId";
pStmt = tokenConn.prepareStatement(query);
pStmt.setString(1, user.getFirstName());
pStmt.setString(2, user.getMiddleName());
pStmt.setString(3, user.getLastName());
pStmt.setString(4, user.getFacilityName());
pStmt.setString(5, sysId.getSystemId());
pStmt.setDate(6, new java.sql.Date(Calendar.getInstance()
.getTime().getTime()));
resultSet = pStmt.executeQuery();
TIA
We're migrating this from WAS 5 to WAS 7 and we're stumped as to why this is now causing a problem. The executeQuery() line is throwing a SQLException saying that it's not returning a ResultSet. Does anyone know what has changed over the course of WAS's life that's not allowing this to work anymore? Is this a JDBC upgrade, or JRE thing?? I've googled around, but I'm really not sure what I should be searching for, so my searches have been unfruitful.
query = "insert into ST_Users ";
query += "(ST_U_First_Name, ST_U_Middle_Name,
ST_U_Last_Name, ST_U_Facility_Name,
ST_U_Last_Trans_ID, ST_U_Last_Trans_Time) ";
query += "values (?,?,?,?,?,?)";
query += ";select SCOPE_IDENTITY() as UserId";
pStmt = tokenConn.prepareStatement(query);
pStmt.setString(1, user.getFirstName());
pStmt.setString(2, user.getMiddleName());
pStmt.setString(3, user.getLastName());
pStmt.setString(4, user.getFacilityName());
pStmt.setString(5, sysId.getSystemId());
pStmt.setDate(6, new java.sql.Date(Calendar.getInstance()
.getTime().getTime()));
resultSet = pStmt.executeQuery();
TIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您有两个疑问。您应该使用
executeUpdate()
执行第一个,然后使用executeQuery()
执行第二个。You have two queries there. You should execute the first one with
executeUpdate()
, and then execute the second one withexecuteQuery()
.我意识到这不是一个直接的答案,但我认为您可以通过使用 JDBC api 生成的密钥功能来执行相同的操作(即返回生成的密钥)。
我怀疑在 WAS 深处的某个地方,上面看起来只是一个插入语句,所以它跳过了结果集。
I realise this isn't a straight answer but I think you could do the same thing (ie. return a generated key) by using the generated key features of the JDBC api.
I suspect that somewhere in the depths of WAS the above looks like just an insert statement, so it skips the result set.