ResultSet update row is not working

后端 未结 2 1335
醉梦人生
醉梦人生 2021-01-20 17:51

I want to update raw in my ResultSet while I looping through the result set. Following is my code

try {
    String query=\"SELECT * FROM smsmessage WHERE rec         


        
2条回答
  •  粉色の甜心
    2021-01-20 18:13

    As the stacktrace tells, you have to create a statement that allows its resultset to be updateable:

    PreparedStatement prepStmt= conn.prepareStatement(query,
        ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
    

    From the API of ResultSet (http://docs.oracle.com/javase/7/docs/api/java/sql/ResultSet.html):

    A default ResultSet object is not updatable and has a cursor that moves forward only. Thus, you can iterate through it only once and only from the first row to the last row. It is possible to produce ResultSet objects that are scrollable and/or updatable. The following code fragment, in which con is a valid Connection object, illustrates how to make a result set that is scrollable and insensitive to updates by others, and that is updatable. See ResultSet fields for other options.

       Statement stmt = con.createStatement(
                                      ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
       ResultSet rs = stmt.executeQuery("SELECT a, b FROM TABLE2");
       // rs will be scrollable, will not show changes made by others,
       // and will be updatable
    

提交回复
热议问题