Re: JDBC and Insert a new row after the last position
Posted in 2005
Topics: Connectivity: ODBC / JDBC / .NET, Java & JDBC Development
1) try to close rs and open it before sentence rs.first() 2) Or instead of it try ResultSet.TYPE_SCROLL_SENSITIVE >superboer wrote: > Jdbc V 2.21.JC3 engine 9.30 > > example taken from UpdateCursor1.java: > > when i read the documentation about resultset.insertRow() it inserts a row > in the database table and in the resultset. > > when i try to fetch all the records in the resultset the last inserted row > is not there. > > the table tab has only one row in it (1,"one",1); > > code fragment: > > System.out.println("Use rowid in the query"); > pstmt = conn.prepareStatement("select *, rowid from tab ", > ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); > rs = pstmt.executeQuery(); > System.out.println("Insert a new row after the last position"); > rs.last(); > rs.moveToInsertRow(); > rs.updateInt(1,999); > rs.updateString(2,"z"); > rs.updateFloat(3,(float)99.9); > rs.insertRow(); > rs.moveToCurrentRow(); > > > rs.first(); > > System.out.println("insertRow() " + rs.getInt(1) +":"+ > rs.getString(2) +":"+ > rs.getFloat(3) +":"+ > // rs.getInt(4) + > ":" > ); > > while( rs.next() ){ > System.out.println("insertRow() " + rs.getInt(1) +":"+ > rs.getString(2) +":"+ > rs.getFloat(3) +":"+ > rs.getInt(4) + > ":" > ); > > after the code above i expect > insertRow() 1:1 :1.0: > insertRow() 999:z :99.9:285: > > however i get: > insertRow() 1:1 :1.0: > > what am i missing?? or does it works as it should do. > > comments are welcome. > > Thanks > > Superboer
Hello Emilio, First of all thanks for the responce; > 1) try to close rs and open it before sentence rs.first() open does not exist in resultset ??!! i can not reexecute query since the last added row may not be found due to the where clause in the qry which created the resultset. > 2) Or instead of it try ResultSet.TYPE_SCROLL_SENSITIVE fails with insertRow() failed: java.sql.SQLException: Invalid argument(s). So any comments are welcome Superboer. emilio <emiliobr@terra.es> wrote in message news:<w4JRd.484322$A7.704904@telenews.teleline.es>... > 1) try to close rs and open it before sentence rs.first() > 2) Or instead of it try ResultSet.TYPE_SCROLL_SENSITIVE > >superboer wrote: > > > Jdbc V 2.21.JC3 engine 9.30 > > > > example taken from UpdateCursor1.java: > > > > when i read the documentation about resultset.insertRow() it inserts a row > > in the database table and in the resultset. > > > > when i try to fetch all the records in the resultset the last inserted row > > is not there. > > > > the table tab has only one row in it (1,"one",1); > > > > code fragment: > > > > System.out.println("Use rowid in the query"); > > pstmt = conn.prepareStatement("select *, rowid from tab ", > > ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); > > rs = pstmt.executeQuery(); > > System.out.println("Insert a new row after the last position"); > > rs.last(); > > rs.moveToInsertRow(); > > rs.updateInt(1,999); > > rs.updateString(2,"z"); > > rs.updateFloat(3,(float)99.9); > > rs.insertRow(); > > rs.moveToCurrentRow(); > > > > > > rs.first(); > > > > System.out.println("insertRow() " + rs.getInt(1) +":"+ > > rs.getString(2) +":"+ > > rs.getFloat(3) +":"+ > > // rs.getInt(4) + > > ":" > > ); > > > > while( rs.next() ){ > > System.out.println("insertRow() " + rs.getInt(1) +":"+ > > rs.getString(2) +":"+ > > rs.getFloat(3) +":"+ > > rs.getInt(4) + > > ":" > > ); > > > > after the code above i expect > > insertRow() 1:1 :1.0: > > insertRow() 999:z :99.9:285: > > > > however i get: > > insertRow() 1:1 :1.0: > > > > what am i missing?? or does it works as it should do. > > > > comments are welcome. > > > > Thanks > > > > Superboer