This question already has answers here:
updateLong not allowed in ResultSet

(3个答案)


1年前关闭。




我已经阅读了关于stackoverflow(以及网络其他地方)的所有“可更新”文章,但无济于事。我的代码运行良好,然后停止了,说结果集不可更新。这涉及我在JDBC derby数据库中使用的4个数据文件。这些文件都有密钥。我不知道还能去哪里。我在下面编写了测试代码来演示该问题。
     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( ) );
   }
}

最佳答案

根据Derby文档(例如here),您不能在可更新的结果集中使用ORDER BY。

关于java - ResultSet不可更新,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25659577/

10-10 13:07