This discussion is archived
3 Replies Latest reply: Mar 31, 2013 8:44 PM by rp0428 RSS

RE: CONCUR_UPDATEABLE not working

Amasoni Newbie
Currently Being Moderated
Hello all!
I have the following code which when i run claims my recordset doesn't support updateable record sets when i moveToInsertRow() .
1007 to indicate ResultSet.CONCUR_READ_ONLY
Could it be that my driver does not support updatable result sets?? How sad if so. I'm using ojdbc14.jar and a Oracle 10g database.
Thnx so much.

//This program claims updateable resultsets are not supported (by my driver ie. ojdbc14.jar).
import java.sql.*;

public class InsertRows {
     public static void main(String args[]) {
          String host="Francis-PC";
          int port=1521;
          String sid="orcl";
          String url = "jdbc:oracle:thin:@" host":"+port+":"+sid;
          String myUserName="abiri";
          String myPassword="abel";
          Connection con;
          Statement stmt;

          try {
               Class.forName("oracle.jdbc.OracleDriver");
          }
          catch(java.lang.ClassNotFoundException e) {
               System.err.print("ClassNotFoundException: ");
               System.err.println(e.getMessage());
          }

          try {
               con = DriverManager.getConnection(url,
                         myUserName, myPassword);
               stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                         ResultSet.CONCUR_UPDATABLE);
               ResultSet uprs = stmt.executeQuery("SELECT * FROM COFFEES");
               int concurrency = uprs.getConcurrency();
               System.out.println("Concurrency code: "+concurrency);
               
               uprs.moveToInsertRow();
               uprs.updateString("COF_NAME", "Kona");
               uprs.updateInt("SUP_ID", 150);
               uprs.updateFloat("PRICE", 10.99f);
               uprs.updateInt("SALES", 0);
               uprs.updateInt("TOTAL", 0);
               uprs.insertRow();
               
               uprs.updateString("COF_NAME", "Kona_Decaf");
               uprs.updateInt("SUP_ID", 150);
               uprs.updateFloat("PRICE", 11.99f);
               uprs.updateInt("SALES", 0);
               uprs.updateInt("TOTAL", 0);
               uprs.insertRow();
               
               uprs.beforeFirst();
               System.out.println("Table COFFEES after insertion:");
               while (uprs.next()) {
                    String name = uprs.getString("COF_NAME");
                    int id = uprs.getInt("SUP_ID");
                    float price = uprs.getFloat("PRICE");
                    int sales = uprs.getInt("SALES");
                    int total = uprs.getInt("TOTAL");
                    System.out.print(name + " " + id + " " + price);
                    System.out.println(" " + sales + " " + total);
               }
               uprs.close();
               stmt.close();
               con.close();
          }
          catch(SQLException ex) {
               System.err.println("SQLException: " + ex.getMessage());
          }
     }
}
  • 1. Re: RE: CONCUR_UPDATEABLE not working
    rp0428 Guru
    Currently Being Moderated
    >
    I have the following code which when i run claims my recordset doesn't support updateable record sets when i moveToInsertRow() .
    1007 to indicate ResultSet.CONCUR_READ_ONLY
    >
    Try specifying all of the columns instead of using 'SELECT *'
    ResultSet uprs = stmt.executeQuery("SELECT * FROM COFFEES");
    This gives a non-updateable result set
    ResultSet uprs = stmt.executeQuery("SELECT * FROM EMP");
    While this result set is updateable
    ResultSet uprs = stmt.executeQuery("SELECT empno, ename, job, mgr, hiredate, sal, comm, deptno FROM EMP");
  • 2. Re: RE: CONCUR_UPDATEABLE not working
    axsa Newbie
    Currently Being Moderated
    Change the line SELECT to extract alll fields not just (*)

    ResultSet uprs = stmt.executeQuery("select COF_NAME,SUP_ID,PRICE,SALES,TOTAL from COFFEES");

    SQLDEVELOPER EXPORT VERIFICATION:
    When completed do an export from sqldeveloper to see the actual output
    -----------------------------------------------------------------------------------------------
    End of sqldeveloper export....
    ------------------------------------------------------------------------------------------------
    http://www.java2s.com/Code/Java/Database-SQL-JDBC/InsertRow2.htm

    Edited by: axsa on Mar 31, 2013 5:20 PM
  • 3. Re: RE: CONCUR_UPDATEABLE not working
    rp0428 Guru
    Currently Being Moderated
    DEAD THREAD!

    Please don't revive year old threads that have already been answered.

    And you have no reason to respone to my post since I am not the one with the problem . OP posted the thread.

    It's great that you want to contribute to the forums buy you need to focus on current, unanswered threads and respond to the people you are providing comments to, not just the last person in the thread.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points