2013-10-01 14 views
6

sto ottenendo questo erroreerrore MYSQL: com.mysql.jdbc.NotUpdatable

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

So che questo errore è per quanto riguarda la chiave primaria, ma per tutti i miei tavoli inizialmente ho inserire una key.So primaria per questa tabella inoltre ho una chiave primaria. Sto postando parte del mio codice.

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

Dimmi solo se qualcosa sta andando storto in questo code.please aiuto. Questo è il mio 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 |    | 
+----------------+---------------+------+-----+---------+----------------+ 
+0

Non hai mostrato come hai assegnato l'istruzione ('st'). È necessario impostarlo aggiornabile nella chiamata 'createStatement'. –

+1

Questo è anche lì Statement st = con.createStatement (ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); –

+0

Hai provato ad aggiungere la clausola "FOR UPDATE" a SELECT? –

risposta

1

È necessario aggiornare la riga subito dopo aver recuperato esso (per l'aggiornamento e rs.updateRow(),

O

si deve scrivere un UPDATE tablename set = where istruzione per aggiornare una riga in qualsiasi momento

0

La query non può utilizzare le funzioni Prova a rimuovere "rand()" dalla stringa di query SQL.
Vedere Specifiche API JDBC 2.1, sezione 5.6 per ulteriori dettagli.