Forums Register Login

ResultSet is not updateable.

+Pie Number of slices to send: Send
jdbc to SqlServer2000.
when I insert some records to dasebase,a error occured
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]ResultSet is not updateable.
How to resolve the problem? thanks!
+Pie Number of slices to send: Send
Without seeing your code I can only guess. When you created the Statement object, did you pass ResultSet.CONCUR_UPDATABLE to the Connection so the ResultSet would be updatable?
+Pie Number of slices to send: Send
Did you specify ResultSet.CONCUR_UPDATEABLE when you created the Statement object? From Sun's online API documentation for Connection.createStatement() method:

Result sets created using the returned Statement object will by default be type TYPE_FORWARD_ONLY and have a concurrency level of CONCUR_READ_ONLY.

Check the constants in the Field Summary for the online ResultSet API documentation at Sun.
http://java.sun.com/j2se/1.4.2/docs/api/index.html
HTH,
Joe
+Pie Number of slices to send: Send
I created the statement like this:
Statement stmt= con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
but it still report the error:java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]ResultSet is not updateable.
is any other reasons can cause the error? thanks a lot!
+Pie Number of slices to send: Send
 

You might note that just specifying that a result set be updatable does not guarantee that the result set you get is updatable. If a driver does not support updatable result sets, it will return one that is readonly. The query you send can also make a difference. In order to get an updatable result set, the query must generally specify the primary key as one of the columns selected, and it should select columns from only one table.
The following line of code checks whether the ResultSet object uprs is updatable.
int concurrency = uprs.getConcurrency();
The variable concurrency will be one of the following:
1007 to indicate ResultSet.CONCUR_READ_ONLY
1008 to indicate ResultSet.CONCUR_UPDATABLE


The JDBC Tutorial, chapter 3
+Pie Number of slices to send: Send
thanks Joe
I get the concurrency, it is 1007, so my resultset is readonly, I don't know how to set the rs to be updateable.
here is my code:
---------------------------------------------------------------
String getNoRowSql = "SELECT mytable.* FROM mytable where col_primay is null"
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery(getNoRowsSql);
//here I get the rs.concurrency = 1007
rs.moveToInsertRow(); // moves cursor to the insert row
rs.updateString(col_1,value1);
//the error occured here, when set the col_1's value as value1
rs.updateString(col_2,value2);
rs.updateString(col_3,value3);
rs.updateString(col_4,value4);
rs.insertRow(); // insert a record to database
rs.moveToCurrentRow();
-----------------------------------------------------------------
I think the getNoRowSql may be the reason. How to make the resultset updateable? thanks a lot!
+Pie Number of slices to send: Send
Are you using latest version of the driver?
MS SQL Server 2000 JDBC Driver SP2?
+Pie Number of slices to send: Send
Yes,Joe
I am using MS SQL Server 2000 JDBC Driver SP2.
I can get the updateable resultset like this:
------------------------------------------------------------
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;User=sa;Password=123");
stmt= conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
sql="select * from mytable where col_primay is null";
rs=stmt.executeQuery(sql);
System.out.println("concurrency = "+rs.getConcurrency());
//here concurrency=1008
------------------------------------------------------------
in my program,I used ConnectionPool to establish connections,maybe there are something wrong with the connection which create by the ConnectionPool.but I can also do almost all operates to resultset except update. What is the reason?
Is a bad connection can cause the resultset not updateable?
this problem of "resultset is not updateable" troubled me too much.
thanks for your help,Joe.
With Regards!
Sincerely Welsh
+Pie Number of slices to send: Send
 

Originally posted by Welsh Ding:

I can get the updateable resultset like this:


So what are you doing differently between this code and the code that won't work? A "bad connection" would fail with the getConnection() or createStatement() call.
Of course, I found a very beautiful couch. Definitely. And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 10241 times.
Similar Threads
Updatable resultsets
ResultSet constants
Get Updated Record
Updatable AND Scrollable Recordsets in Sybase
Cursor in DB2
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 04:33:42.