只读结果集的操作无效:deleterow()

时间:2014-05-07 03:01:07

标签: java sql netbeans

嘿伙计们,我目前正在将两个表合并为一个,以便在GUI中输出。当我单击删除按钮时,我被告知"对于只读结果集的无效操作:deleterow()。这有什么问题?

Connection con;
Statement stmt;
ResultSet rs;
int curRow = 0;

public SectionPage() {
    initComponents();
    DoConnect();
}

public void DoConnect() {
    try {
        String host = "***";
        String uName = "*****";
        String uPass = "****";
        con = DriverManager.getConnection(host, uName, uPass);

        stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
        String sql = "SELECT Course_Name, Credit_Hours, Section_Number, Instructor, Semester,Department FROM Course_Table , Section_Table WHERE Section_Table.Course_Number = Course_Table.Course_Number ";
        rs = stmt.executeQuery(sql);

        rs.next();
        String coursename = rs.getString("Course_Name");
        String credithours = rs.getString("Credit_Hours");
        String department = rs.getString("Department");
        String instructor = rs.getString("Instructor");
        String semester = rs.getString("Semester");
        String section = rs.getString("Section_Number");
        jTextField1.setText(coursename);
        jTextField3.setText(instructor);
        jTextField4.setText(credithours);
        jTextField5.setText(section);
        jTextField6.setText(semester);
        jTextField7.setText(department);

        jButton1.setEnabled(true);
        jButton2.setEnabled(true);
        jButton3.setEnabled(true);
        jButton4.setEnabled(true);
        jButton5.setEnabled(true);
        jButton6.setEnabled(true);
        jButton7.setEnabled(true);
        jButton8.setEnabled(true);
        jButton9.setEnabled(false);
        jButton10.setEnabled(false);


    } catch (SQLException err) {
        JOptionPane.showMessageDialog(SectionPage.this, err.getMessage());
    }
}


private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    try {
        rs.deleteRow();
        stmt.close();
        rs.close();
        stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
        String sql = "SELECT Course_Name, Credit_Hours, Section_Number, Instructor, Semester,Department " +
                "FROM Course_Table , Section_Table WHERE Section_Table.Course_Number = Course_Table.Course_Number ";

        rs = stmt.executeQuery(sql);

        rs.next();
        String coursename = rs.getString("Course_Name");
        String credithours = rs.getString("Credit_Hours");
        String department = rs.getString("Department");
        String instructor = rs.getString("Instructor");
        String semester = rs.getString("Semester");
        String section = rs.getString("Section_Number");
        jTextField1.setText(coursename);
        jTextField3.setText(instructor);
        jTextField4.setText(credithours);
        jTextField5.setText(section);
        jTextField6.setText(semester);
        jTextField7.setText(department);
    } catch (SQLException err) {
        JOptionPane.showMessageDialog(SectionPage.this, err.getMessage());
    }
}

0 个答案:

没有答案