gpt4 book ai didi

java.sql.SQLException : Can not issue data manipulation statements with executeQuery() 异常

转载 作者:行者123 更新时间:2023-11-30 23:02:13 39 4
gpt4 key购买 nike

<分区>

我似乎无法解决这个问题。我需要 ResultSet 来获取实际的对象。错误是:java.sql.SQLException:无法使用 executeQuery() 发出数据操作语句。rs = pst.executeQuery();。代码:

Connection con = null;
PreparedStatement pst = null;
ResultSet rs = null;

String url = null; //Set, but not visible in code.
String user = null; //Set, but not visible in code.
String password = null; //Set, but not visible in code.

public Object get(String table, String key){
try {
con = DriverManager.getConnection(url, user, password);

String query = "SELECT * FROM `" + table + "` WHERE key = ?;";
pst = con.prepareStatement(query);

pst.setString(1, key);
pst.executeUpdate();

rs = pst.executeQuery();

rs.next();

return rs.getObject(1);

} catch (SQLException ex) {

return null;

} finally {
try {
if (rs != null) {
rs.close();
}
if (pst != null) {
pst.close();
}
if (con != null) {
con.close();
}

} catch (SQLException ex) {

return null;

}
}
}

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com