当前位置: 代码迷 >> J2SE >> 执行deleteRow()之后结果集被关闭?解决方案
  详细解决方案

执行deleteRow()之后结果集被关闭?解决方案

热度:99   发布时间:2016-04-24 00:50:16.0
执行deleteRow()之后结果集被关闭?
Java code
public void actionPerformed(ActionEvent ae) {                ResultSet rs = StudentInformation.getResultSet();                int selectedRow = InformationTable.getSelectedRowIndex();                if (selectedRow == -1) {                    JOptionPane.showMessageDialog(                            OperationPanel.this.getParent(), "错误操作:对无效列的删除!",                            "删除失败", JOptionPane.OK_OPTION);                    return;                }                try {                    rs.absolute(selectedRow + 1);                    rs.deleteRow();                    JOptionPane.showMessageDialog(OperationPanel.this.getParent(),                            "删除成功!", "删除成功", JOptionPane.WARNING_MESSAGE);                } catch (SQLException e) {                    e.printStackTrace();                    JOptionPane.showMessageDialog(OperationPanel.this.getParent(),                            "有个未知错误!请联系写这个程序的天才!", "删除失败", JOptionPane.OK_OPTION);                }            }


这是为我的按钮添加的监听器。当我第一次选中JTable中的那一行时,点这个按钮,删除成功,然后我再做任何需要使用结果集的操作,都会报错:

com.microsoft.sqlserver.jdbc.SQLServerException: 该连接已关闭
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.checkClosed(SQLServerConnection.java:388)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.checkClosed(SQLServerStatement.java:978)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.checkClosed(SQLServerResultSet.java:375)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.last(SQLServerResultSet.java:1456)
at huangjin.frame.ResultTableModel.getRowCount(ResultTableModel.java:44)
at javax.swing.JTable.getRowCount(Unknown Source)
at javax.swing.JTable.getCellRect(Unknown Source)
at javax.swing.JTable.valueChanged(Unknown Source)
at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
at javax.swing.DefaultListSelectionModel.changeSelection(Unknown Source)
at javax.swing.DefaultListSelectionModel.changeSelection(Unknown Source)
at javax.swing.DefaultListSelectionModel.setSelectionInterval(Unknown Source)
at javax.swing.JTable.changeSelectionModel(Unknown Source)
at javax.swing.JTable.changeSelection(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI$Handler.adjustSelection(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI$Handler.mousePressed(Unknown Source)
at java.awt.AWTEventMulticaster.mousePressed(Unknown Source)
at java.awt.AWTEventMulticaster.mousePressed(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
  相关解决方案