gpt4 book ai didi

java - 结果集关闭后,我收到“操作不允许”消息

转载 作者:太空宇宙 更新时间:2023-11-04 09:29:56 24 4
gpt4 key购买 nike

我正在提取大约 10,000 个患者 ID,同时在执行加密后我想将它们插入到另一个表中,但出现此错误

java.sql.SQLException: Operation not allowed after ResultSet closed.

Connection conn=null;
PreparedStatement pst=null;
try{
conn = DriverManager.getConnection(constring,username,password);
System.out.println("connected");

Statement stmt=(Statement) conn.createStatement();

ResultSet srs = stmt.executeQuery(
"select patient_id from patient");

while (srs.next()) {
patient_id = srs.getInt("patient_id");

System.out.println(patient_id);
JavaApplication5 o=new JavaApplication5(key);

g=patient_id;
o.c=main.g;
s=o.encrypt(o.c,key);
System.out.println(s);
String insert = "Insert into fyp1 (patient_id) values ('"+s+"')";
stmt.executeUpdate(insert);
}
}
catch(SQLException e){System.out.println(e);

最佳答案

您需要创建另一个语句,因为第一个 ResultSet srsstmt.executeUpdate(insert); 处再次运行时已关闭。

请参阅 JavaDocs 中的 ResultSet

Note: A ResultSet object is automatically closed by the Statement object that generated it when that Statement object is closed, re-executed, or is used to retrieve the next result from a sequence of multiple results.

顺便说一句。请始终发布完整的堆栈跟踪,例如以及相应的行号。

关于java - 结果集关闭后,我收到“操作不允许”消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57206841/

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