我试图从一个try catch块中的两个表中获取值但是通过SqlException操作不允许关闭结果。
try {
JdbcConnection.connectDB();
String sql = "SELECT * FROM projects where username = '" + username
+ "' && project_id ='" + p_id + "'";
String sql1 = "SELECT * FROM rewards where project_id ='" + p_id
+ "'";
ResultSet rs = JdbcConnection.stmt.executeQuery(sql);
ResultSet rs1 = JdbcConnection.stmt.executeQuery(sql1);
while (rs.next()) {
fname.setText(rs.getString(3).toString());
lname.setText(rs.getString(4).toString());
uname.setText(rs.getString(5).toString());
pwd.setText(rs.getString(6).toString());
addr.setText(rs.getString(7).toString());
ctry.setText(rs.getString(8).toString());
acc_no.setText(rs.getString(9).toString());
}
while (rs1.next()) {
rwd1.setText(rs1.getString(2));
rwd2.setText(rs1.getString(4));
rwd3.setText(rs1.getString(6));
rwd4.setText(rs1.getString(8));
rwd5.setText(rs1.getString(10));
}
rs.close();
} catch (SQLException sqlexc) {
JOptionPane.showMessageDialog(null, "" + sqlexc);
}
代码中可能出现什么问题?
的printStackTrace()
java.sql.SQLException: Operation not allowed after ResultSet closed
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
at com.mysql.jdbc.ResultSetImpl.checkClosed(ResultSetImpl.java:804)
at com.mysql.jdbc.ResultSetImpl.next(ResultSetImpl.java:6986)
at project.ProjectDetails.<init>(ProjectDetails.java:116)
at project.ArtistProject.mouseClicked(ArtistProject.java:198)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253)
at java.awt.Component.processMouseEvent(Component.java:6041)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
at java.awt.Component.processEvent(Component.java:5803)
at java.awt.Container.processEvent(Container.java:2058)
at java.awt.Component.dispatchEventImpl(Component.java:4410)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3995)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
at java.awt.Container.dispatchEventImpl(Container.java:2102)
at java.awt.Window.dispatchEventImpl(Window.java:2429)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
答案 0 :(得分:1)
我想你应该为stmt
创建不同的陈述(rs1
)。