Question

I am getting this error

javax.servlet.ServletException: com.mysql.jdbc.NotUpdatable: Result Set not updatable.

I know this error is regarding the primary key but for all my tables I initially insert a primary key.So for this table also I have a primary key.I am posting part of my code.

Statement st=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=st.executeQuery("Select * from test3 order by rand() limit 5");
List arrlist = new ArrayList();
while(rs.next()){
   String xa =rs.getString("display");
   if(xa.equals("1")){
      arrlist.add(rs.getString("question_text"));
   }
   rs.updateString("display", "0");
   rs.updateRow();

Just tell me if something is going wrong in this code.please help. This is my database

+----------------+---------------+------+-----+---------+----------------+
| Field          | Type          | Null | Key | Default | Extra          |
+----------------+---------------+------+-----+---------+----------------+
| id             | int(11)       | NO   | PRI | NULL    | auto_increment |
| index_question | varchar(45)   | YES  |     | NULL    |                |
| question_no    | varchar(10)   | YES  |     | NULL    |                |
| question_text  | varchar(1000) | YES  |     | NULL    |                |
| file_name      | varchar(128)  | YES  |     | NULL    |                |
| attachment     | mediumblob    | YES  |     | NULL    |                |
| display        | varchar(10)   | YES  |     | NULL    |                |
+----------------+---------------+------+-----+---------+----------------+
Was it helpful?

Solution

You have to update the row immediately after you have fetched it (FOR UPDATE and rs.updateRow(),

OR

you have to write an UPDATE tablename set = where statement to update a row at any time

OTHER TIPS

The query can not use functions. Try removing the "rand()" from the SQL query string.
See the JDBC 2.1 API Specification, section 5.6 for more details.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top