【发布时间】:2013-10-04 12:35:20
【问题描述】:
我正在创建一个程序来重命名 mysql 中的数据库。 我在所有事情上都取得了成功,并且成功地发生了。但在我的脚本结束时,它显示一个错误/异常,说“在 ResultSet 关闭后不允许操作”。我真的不知道为什么即使在研究了这个错误之后也会出现这个错误。 虽然完整的操作成功完成并且数据库被重命名。 这是我的代码->
String x = (String) jComboBox1.getSelectedItem(); //jComboBox1 contains the name of current database selected
String z = JOptionPane.showInputDialog("Please enter new name for Database"); //Where user enters the name for new database.
new CustComm().setVisible(false); //Frame that carries the names of tables.
try{
Class.forName("java.sql.DriverManager");
Connection con = (Connection)
DriverManager.getConnection("jdbc:mysql://localhost:"+GlobalParams.portvar+"/",""+k,""+j);
Statement stmnt = (Statement) con.createStatement();
String query = "use "+x;
stmnt.executeQuery(query);
String query2 = "show tables";
ResultSet rs = stmnt.executeQuery(query2);
while (rs.next()){
String dname = rs.getString("Tables_in_"+x);
if(CustComm.jTextArea1.getText().equals("")){
CustComm.jTextArea1.setText(CustComm.jTextArea1.getText()+dname);
}
else{
CustComm.jTextArea1.setText(CustComm.jTextArea1.getText()+"\n"+dname);
}
String y = CustComm.jTextArea1.getText();
Scanner scanner = new Scanner(y);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
String query3 = "Create database "+z;
stmnt.executeUpdate(query3);
//alter table my_old_db.mytable rename my_new_db.mytable
String query4 = "RENAME TABLE "+x+"."+line+" TO "+z+"."+line;
stmnt.executeUpdate(query4);
String query5 = "drop database "+x;
stmnt.executeUpdate(query5);
}}}
catch(Exception e){
JOptionPane.showMessageDialog(this,e.getMessage());
}
请帮忙。
【问题讨论】:
-
而不是 e.getMessage 使用 e.printstacktrace 并发布错误消息。同时指出它在哪一行给出了异常
-
您好,感谢您的回复。然后它会引发以下错误(抱歉,错误太长,无法在此处发布,所以我提供了链接)-> pastebin.com/wt7UwwuE 我无法确定导致此错误的行:/ 甚至尝试阅读并遵循它给出的错误,但没有帮助。自从我遇到此错误以来已经有一天了,在我尽力删除它之后我在这里发布。由于我对 java 还很陌生,所以我无法弄清楚导致线路输出的错误:(请帮忙。是的,还有一件事,为此目的的编码从第 443 行开始,到 478 行结束。