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( ) );
}
}
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