ResultSet: Exception: set type is TYPE_FORWARD_ONLY — why?

后端 未结 9 1379
春和景丽
春和景丽 2020-12-15 07:08

I have very simple code:

pstat=con.prepareStatement(\"select typeid from users where username=? and password=?\");             
pstat.setString(1, username);         


        
9条回答
  •  无人及你
    2020-12-15 07:22

    The Java 8 documentation states the following:

    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
    

提交回复
热议问题