0

我试图从一个 try catch 块中的两个表中获取值,但是通过 SqlException Operation not allowed ater ResultSet 关闭。

    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);
    }

代码中可能有什么问题?

打印堆栈跟踪()

    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)
4

1 回答 1

1

我想你应该stmtrs1.

于 2013-10-11T01:24:06.940 回答