import java.sql.*; import javax.sql.*; import java.sql.*; import javax.sql.rowset.*; import com.sun.rowset.*; public class RowSetTest { public static void main(String[] args) throws Exception{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:oradsn","scott","tiger"); Statement stmt=con.createStatement(1004,1008); ResultSet rs=stmt.executeQuery("select * from emp7"); JdbcRowSet jrs=new JdbcRowSetImpl(rs); jrs.afterLast(); while (jrs.previous()) { System.out.println(jrs.getInt(1)+"\t"+jrs.getString(2)+"\t"+jrs.getString(3)); } jrs.absolute(6); jrs.deleteRow(); System.out.println("6th row deleted"); rs.close(); stmt.close(); } } D:\>javac RowSetTest.java RowSetTest.java:13: warning: com.sun.rowset.JdbcRowSetImpl is Sun proprietary AP I and may be removed in a future release JdbcRowSet jrs=new JdbcRowSetImpl(rs); ^ 1 warning D:\>java RowSetTest D:\>java RowSetTest Exception in thread "main" java.sql.SQLException: [Microsoft][ODBC Driver Manage r] Invalid cursor state at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957) at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114) at sun.jdbc.odbc.JdbcOdbc.SQLGetDataInteger(JdbcOdbc.java:3811) at sun.jdbc.odbc.JdbcOdbcResultSet.getDataInteger(JdbcOdbcResultSet.java :5638) at sun.jdbc.odbc.JdbcOdbcResultSet.getInt(JdbcOdbcResultSet.java:583) at com.sun.rowset.JdbcRowSetImpl.getInt(JdbcRowSetImpl.java:946) at RowSetTest.main(RowSetTest.java:16) plz find above problem............
hi, friend I think you are indicating an invalid row for deleting either the row is not available in the database table or you are putting the insert row. Put the valid row number or any other row number which is available in the table.
Here I am giving a Java code and hope this will helpful for you. In this code I have 4 records in my emp table and found the same error what you have founded, when I have provided the row number 5 to position the cursor. i.e. jdbcRs.absolute(5) and jdbcRs.deleteRow(). And the error will also be occurred when you will provide the insert row number in my example row number 4. So provide the valid row number.
import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; import java.sql.ResultSet; import java.sql.SQLException; import javax.sql.rowset.JdbcRowSet; import com.sun.rowset.JdbcRowSetImpl; public class JavaJDBCRowSetExample { public static void main(String[] args) throws SQLException { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:swing"); String sql = "select * from emp"; Statement ps = con.createStatement(1004, 1008); ResultSet rs = ps.executeQuery(sql); JdbcRowSet jdbcRs = new JdbcRowSetImpl(rs); jdbcRs.afterLast(); System.out.println("Records before deleting of row"); System.out.println("id \t fName \t lName \t address"); while (jdbcRs.previous()) { int id = jdbcRs.getInt("id"); String fName = jdbcRs.getString("fName"); String lName = jdbcRs.getString("lName"); String address = jdbcRs.getString("address"); System.out.println(id+" \t "+fName+" \t "+lName+" \t "+address); } boolean bol = jdbcRs.absolute(3); int i = jdbcRs.getRow(); System.out.println("Deleting row no. "+i+"....."); jdbcRs.deleteRow(); jdbcRs.refreshRow(); System.out.println("row no. "+i+" is deleted"); jdbcRs.afterLast(); System.out.println("Records after deleting of row"); System.out.println("id \t fName \t lName \t address"); while (jdbcRs.previous()) { int id = jdbcRs.getInt("id"); String fName = jdbcRs.getString("fName"); String lName = jdbcRs.getString("lName"); String address = jdbcRs.getString("address"); System.out.println(id+" \t "+fName+" \t "+lName+" \t "+address); } rs.close(); ps.close(); } catch(Exception ex) { System.out.println(ex); } } }
Ads