即使设置为CONCUR_UPDATABLE,ResultSet也不可更新

时间:2018-04-19 22:56:44

标签: java mysql

我尝试使用下面的代码向我的数据库添加一个新行,即使已在代码中明确说明,我仍然会收到该错误

ResultSet rs12 = null;
                        String sql1 = ("Select admin.* From admin");
                        Statement st1 = cn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
                        rs12 = st1.executeQuery(sql1);
                        if(!rs12.equals(null))
                        {
                            JdbcRowSet regis = new JdbcRowSetImpl(rs12);
                            regis.setConcurrency(java.sql.ResultSet.CONCUR_UPDATABLE);
                            regis.last();
                            int id=Integer.parseInt(regis.getString("id"))+1;
                            regis.moveToInsertRow();
                            regis.updateInt("id", id);
                            regis.updateString("username", adminname);
                            regis.updateString("password", pass);
                            regis.insertRow();
                            regis.moveToCurrentRow();
                            textAdmin.setText("");
                            passwordAdmin.setText("");
                            passwordAdminConfirm.setText("");
                            JOptionPane.showMessageDialog(this, "You have Successfully Registered!");

                            log.close();
                            regis.close();
                        }

我得到以下错误: enter image description here

1 个答案:

答案 0 :(得分:0)

尝试使用ResultSet.TYPE_SCROLL_INSENSITIVE或ResultSet.TYPE_SCROLL_SENSITIVE调用regis.setType