ResultSet is not updatable [duplicate]

坚强是说给别人听的谎言 提交于 2019-11-27 08:33:02

问题


This question already has an answer here:

  • updateLong not allowed in ResultSet 3 answers

I have read all of the "updatable" post on stackoverflow (and elsewhere on the web) but to no avail. My code was working fine then it stopped say the resultset was not updatable. This is across the 4 data files I use in the JDBC derby database. The files all have keys. I don't know where else to look. I wrote the test code below to demonstrate the problem.

     private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {                                      
try {
    String uName = "guest";
    String uPass = "guest";
    String host = "jdbc:derby://127.0.0.1:1527/erTracker";
    Connection erTrackerCon = DriverManager.getConnection( host,uName,uPass );
   // erTrackerCon.setAutoCommit(true);
     milestonesStmt = erTrackerCon.createStatement( ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
    String SQL = "SELECT * FROM milestones order by milestoneID";
    rsMilestones = milestonesStmt.executeQuery( SQL ); 
    String a = "02";
    String b = "M";
    String c = "Move to prospect";
    erTrackerCon.setReadOnly(false);
    int concurrency = rsMilestones.getConcurrency();
    System.out.println("the answer is " + concurrency); // the answer is 1007
    rsMilestones.moveToInsertRow(); // error is: 'moveToInsertRow' not allowed because the ResultSet is not an updatable ResultSet. 
    rsMilestones.updateString("milestoneID", a);
    rsMilestones.updateString("milestoneType",b);
    rsMilestones.updateString("milestoneName", c);
    rsMilestones.insertRow( );  
   //String SQL =  "INSERT INTO milestones (milestoneid,milestonetype,milestongname) VALUES     ('02','M','move to pursue')";
   //rsMilestones = milestonesStmt.executeQuery( SQL );
}                                     
catch ( SQLException err ) {
   System.out.println( err.getMessage( ) );
   }
}

回答1:


According to the Derby documentation (e.g. here) you cannot use ORDER BY in an updatable resultset.



来源:https://stackoverflow.com/questions/25659577/resultset-is-not-updatable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!