UpdateRow() of ResulSet

hi,
to update any row of a table using ResultSet.updateRow() API, is there any condition like, the table should have a primary key compulsorily. I am using some third party implementation of JDBC code and when i try to udpate a table which does not have a primary key with updateRow() API from application, it's giving an exception saying "No primary key for the table".
I dont see any reason for this behavoiur and hope the problem is with the implemetation of JDBC code by the third party. Please let me know your valuable inputs...........

Praveen_Forum wrote:
An updatable result set allows modification to data in a table through
the result set. If the database does not support updatable result
sets, the result sets returned from executeQuery() will be
read-only. To get updatable results, the Statement object used to
create the result sets must have the concurrency type
ResultSet.CONCUR_UPDATABLE.
The query of an updatable result set must specify the primary
key as one of the selected columns and select from only one table.
For some drivers, `SELECT * FROM my_table' will return a read-only
result set, so make sure that you specify the column names.
try {
// Create a statement that will return updatable result sets
Statement stmt = connection.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
// Primary key col_string must be specified so that the result set is updatable
ResultSet resultSet = stmt.executeQuery("SELECT col_string FROM my_table");
} catch (SQLException e) {
what is the point your driving? whatever you copy pasted is not what i asked..... please give me proper answer else dont mislead....

Similar Messages

  • Question about updateRow in ResultSet

    Simple problem. When I update the values in a resultset with:
    rs.updateString("columnName", aString);
    rs.updateRow();the value of columnName is updated, but the values of all the other columns in the row are set to nothing. How do I prevent this from happening? Do I have to update all the column values when using updateRow, i.e getting the values from the resultset and then updating with the same values?
    - Karl XII

    Hi Karl,
    You could try using the following code:
    int numRows = 0;
    int empId = 1223;
    String updateEmp="update employees set department=?
    where id = ?";
    PreparedStatement pstmt =
    conn.prepareStatement(updateEmp);
    pstmt.setString(1,"department");
    pstmt.setInt(2,empId);
    numRows = pstmt.executeUpdate();
    pstmt.close();
    This piece of code would only update the columns that
    you mention in the PreparedStatement SQL query.
    Thanks,
    Rashmi.Thanx. But I have a resultSet that is linked to the database. I to only like to edit the value of a specific column in the resultset... any other suggestions?

  • Problem with updateRow() of resultset

    When using JDBC-ODBC bridge accessing MS SQL Server 8.0.
    I issue the rs.updateRow(), and receive the following error:
    class java.sql.SQLException [Microsoft][ODBC SQL Server
    Driver]Invalid attribute/option identifier
    Any one out there have an idea ???
    Jagpate

    Hi Rolandpish:
    I'm using the following on Windows XP Pro:
    Product : Microsoft SQL Server, Version : Microsoft SQL Server  2000 - 8.00.760 (Intel X86)
               Dec 17 2002 14:22:05
               Copyright (c) 1988-2003 Microsoft Corporation
               Enterprise Evaluation Edition on Windows NT 5.1 (Build 2600: Service Pack 1)
    Driver : SQLServer, Version : 2.2.0029I haven't been able to get ResultSet.CONCUR_UPDATABLE.... how did you managed to get that accomplished (pls don't tell me it's because I'm using an Evaluation Edition).
    ;o)
    V.V.

  • UpdateRow(): ORA-00907 missing right parenthesis???

    This pertains to Oracle8i 8.1.7 JDBC Drivers JDK 1.2.x for NT (classes12.zip) that I just downloaded today from the website.
    I call rset.updateRow() after I update a particular column
    rset.updateString("col_name","whatever")
    and get the following SQLException message.
    ORA-00907: missing right parenthesis.
    I tried to call rset.updateRow() without doing an updateString() and it passes with no exception.
    I've looked at my very simply code over and over and don't see how any of it could be a problem. Is it possible that Oracle released this driver forgetting about a little ")" somewhere in the SQL that it sends to the database in this method?
    Again:
    (1) rset.updateString("col_name","whatever");
    rset.updateRow();
    throws the SQLException
    (2) rset.updateRow();
    is fine by itself
    null

    If you are using the FOR UPDATE in your SELECT stmt, there is a bug.
    See BUG:1811866
    Encountered the same problem myself.
    Was unable to find any further reference to this bug on Oracle's site. Is this still outstanding, and, if so, is there a target date for the fix?

  • ResultSet updateRow() problem

    The RDBMS I am working with is:
    Apache Derby version = 10.1.2.1
    I cannot seem to figure out why this ResultSet update is not working.
    I create the ResultSet with the following:
    Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE, ResultSet.HOLD_CURSORS_OVER_COMMIT);The query that I execute to return the result set contains the primary key, FROM contains only one table, and the query contains no JOINS or UNIONS.
    So then I call next()
    Update all the columns that I am interested in updating, up to this point everything is fine, I can get the column that I updated out, and the values are the updated ones.
    When I call updateRow(), I get: Invalid cursor state - no current row
    But there is a current row, I am updating columns in it and those updates are taking place.
    Any help is appreciated.
    Thanks

    yes, it returns true.
    and it is the row that I am interested in. If
    immediately after the next() I get one of the
    columns, it is the correct value, then I set it using
    updateXXX, then get it out again it is the updated
    value. All as I would expect it to work.
    But on the call to updateRow() - Invalid cursor state
    - no current row.Then I would suspect that the database driver you're using doesn't support updateable resultsets (?)
    You do realize that not all databases support that, right?
    Although it would seem that you should get a different error message in that case, hence the (?) above.

  • Resulset in an html page

    Hi
    I have tried to output an html page based on a resulset of jdbc query , my database of sql server 2005,
    But my code gives me an html page containing table of one row contain null value as the following source
    <html> <body> <table border=1> <caption>Report title</caption><table border=1><tr><td>null
    this my trial
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
      try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                 con = DriverManager.getConnection("jdbc:odbc:MerchandiseCon","sa","sql123#");
                st = con.createStatement( );
    ResultSet rset=st.executeQuery("Select Item_code,Item_Name,item_cost,item_quantity  from Inventory");
       ResultSetMetaData md = rset.getMetaData();
    while(rset.next())
        int count = md.getColumnCount();
          for (int i=1; i<=count; i++) {
          try
                FileOutputStream fs =null;
                try {
                    fs = new FileOutputStream("D:\\Report\\myeport.html");
                catch (FileNotFoundException ex) {
                    Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
               String s = "<html> <body> <table border=1> <caption>Report title</caption>";
    s +="<table border=1>";
    s+=    "<tr>" ;
             s  += "<td>";
             s +=rset.getString(i);
            fs.write(s.getBytes());
       s   += ("</tr>");
       s   +=("</table>");
        s   +=("</body>");
         s   +=("</html>");
             catch (IOException ex) {
                Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
            }catch(NullPointerException e)
         st.close();
                con.close();
         catch(ClassNotFoundException ex)
             ex.printStackTrace();
          catch(SQLException ex)
             ex.printStackTrace();
        }

    The problem lies here in your code
    fs = new FileOutputStream("D:\\Report\\myeport.html");
    you are calling this for every increment of "i" in the for loop.

  • SQL statement, updateString and updateRow

    i need some help by using updateString an updateRow
    i have to update some databases ever 3 months.
    all together 250,000 datasets.
    one row should be read out, modified and written back.
    at the moment i do it like that:
    rs = dbconnect ...(..."select rrn(database),database.row from database)
    while (rs.next())
    str = rs.getString(2);
    i = rs.getInt(1);
    ..executeSqlStatement(..."update database set row = " + str + " where rrn(database) = "+i);
    rs.close();
    but that is very longlasting.
    i tryed it with updateString and updateRow, but it didn't work.
    Is it possible to say SQL, if one hit made, stop the search?
    my statements alsways run through the hole databases, although
    its sure that there is only one hit, especially if the "rrn"-statement is
    included in the condition.
    is

    we use our "own" connect-method, called dbconnect:
    statement = getConnection(x_systemname).createStatement();
    rs = statement.executeQuery(x_sqlstatement);
    return rs;You need to explicitly say it whether you want a ResultSet updatable:
    stm = getConnection(x_systemname)
      .createStatement(
        ResultSet.TYPE_SCROLL_INSENSITIVE,
        ResultSet.CONCUR_UPDATABLE
      );That way you are able to perform updates with updateXXX() methods and updateRow() at the end.

  • Retrieve varchar column from Oracle query in a resulset

    Hi, I'am a begginer in JSP Technologies.
    I've do a small jsp that opens a db connection to an oracle, execute a query a show results.
    When the columns of the query are int I've no problem, the jsp show the columns of the resulset, but when the columns selected are varchars the jsp doesn't show anything....
    Can anyone help me?
    Example:
    Table: CUSTOMERS
    Col1 : ID_COSTUMER int
    Col2: CUSTOMER_NAME varchar
    <%
    Connection canal = null;
    ResultSet tabla = null;
    Statement instruccion=null;
    try { Class.forName("oracle.jdbc.driver.OracleDriver");
    canal=DriverManager.getConnection("jdbc:oracle:thin:@XXXXXXXXXXXXXXXXXXXp");
    instruccion = canal.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
    } catch(java.lang.ClassNotFoundException e){};
    String Query = "SELECT ID_CUSTOMER FROM CUSTOMERS";
    try { tabla = instruccion.executeQuery(Query);
    out.println("<TABLE Border=10 CellPadding=5><TR>");
    out.println("<TD>CUSTOMER</TD></TR>");
    while(tabla.next()) {
    out.println("<TR>");
    out.println("<TD>"+tabla.getString(1)+"</TD>");
    out.println("</TR>"); };
    out.println("</TABLE></CENTER></DIV></HTML>");
    tabla.close(); instruccion.close(); canal.close();}
    catch(SQLException e) {};
    %>Results:
    CUSTOMER
    1
    2
    3
    4
    Doing the change in query:
    SELECT CUSTOMER_NAME FROM CUSTOMERS
    I have not results....
    Thank you.

    sorry, I misplaced an ending code bracket on last one
    I'm not really familiar with doing this inside a jsp.. but there are a few things that you should try to make sure that it isn't a database problem before assuming it is a problem on your jsp.... It is possible you have already tried the following but just to make sure.
    When you do the second query does the first two out.printlns that are before the while still output? If not then your query is incorrect.
    Second I would try
    String Query = "SELECT ID_CUSTOMER,CUSTOMER_NAME FROM CUSTOMERS";
    try { tabla = instruccion.executeQuery(Query);
    out.println("<TABLE Border=10 CellPadding=5><TR>");
    out.println("<TD>CUSTOMER_ID</TD><TD>CUSTOMER_NAME</TD></TR>");
    while(tabla.next()) {
    out.println("<TR>");
    out.println("<TD>"+tabla.getString(1)+"</TD>");
    out.println("<TD>"+tabla.getString(2)+"</TD>");
    out.println("</TR>"); };
    out.println("</TABLE></CENTER></DIV></HTML>");I suspect this will also return nothing.. if that is the case then you need to check your database. If it does infact return values for the ID and nothing for the NAME then I'm not sure at this point what the problem is.

  • How to order a updateable resulset?

    hello
    i use an updateable resulset.
    everything works fine.
    i can scroll forward, backward and can update it.
    but when i add an "order by" to the select statement,
    than i get following error:
    ORA-01732: data manipulation operation not legal on this view
    Cause: An attempt was made to use an UPDATE, INSERT, or DELETE statement on a view that contains expressions or functions or was derived from more than one table. If a join operation was used to create the view or the view contains virtual columns derived from functions or expressions, then the view may only be queried.
    Action: UPDATE, INSERT, or DELETE rows in the base tables instead and restrict the operations on the view to queries.
    now the question is, how can i order an updateabe resultset?
    to use the scroll functionality, i must order the resultset,
    otherwise i do not know in which order the resultset is ...
    any idea?
    thanks a lot!

    Hi useridlh,
    As the error message (you posted) states, you are apparently attempting to update a database view that is based on more than one database table. Oracle does not allow this.
    However, you claim that you are able to update the "ResultSet" if the query does not contain the ORDER BY clause. There are restrictions imposed by Oracle's JDBC drivers on updatable "ResultSet"s.
    Unfortunately, I can't seem to access Oracle's online documentation, so I can't give you the URL, but the limitations are detailed in the JDBC Developer's Guide and Reference. I saw no mention in your post of which Oracle version you are using (nor which JDBC driver you are using),
    so here is a quote from the Oracle 8i documentation:
    In fact, you cannot use ORDER BY for any result set where you will want
    to refetch rows. This applies to scroll-insensitive/updatable result
    sets as well as scroll-sensitive result sets.
    [Chapter 12 - Result Set Enhancements, page 12-10]
    Hope this helps.
    Good Luck,
    Avi.

  • ResultSet updateRow ,insertRow ,deleteRow APIs on table with no PRIMARY KEY

    Hi,
    When I use ResultSet.insertRow , updateRow ,deleteRow API's on a table which contais no primary key column I find the following Exception ,
    java.sql.SQLException: Operation invalid. No primary key for the table
    at com.tandem.sqlmx.Messages.createSQLException(Messages.java:69)
    at com.tandem.sqlmx.SQLMXResultSet.getKeyColumns(SQLMXResultSet.java:3501)
    at com.tandem.sqlmx.SQLMXResultSet.prepareInsertStmt(SQLMXResultSet.java:3652)
    at com.tandem.sqlmx.SQLMXResultSet.insertRow(SQLMXResultSet.java:2073)
    at testdateupdate.main(testdateupdate.java:33)
    It looks like the table needs to have a primary key column to update or insert or delete rows using the ResultSret APIs.
    I use a proprietary JDBC driver. I find the Explanation for this behavior like this ,
    JDBC allows update stmts on tables w/out a primary key defined if the stmt is issued by the application. For updateable ResultSets, a primary key restriction is required to avoid updating more rows than desired.I dont understand this explanation and also I dont find this behavior is some other JDBC drivers that I tried with.
    Some one Please Clarify the same.
    Thanks in Advance.
    Thanks and Regards,
    Jay

    Hi,
    in simple words, when a table does not have primary key you can send update and delete on it only by using a Statement object. When using ResultSet.updateRow or ResultSet.deleteRow the jdbc looks for the primary key on the metadata in order to send the correct where clause to the rdbms. I think that this could maybe work with Oracle DBMS, which has a unique id (ROWID) for each record.
    Kiros

  • Java SP - ResultSet.updateRow causes 100x CPU consumption

    Oracle 11 Enterprise on Windows, with an out-of-the-box installation.
    I select from a table. No where clause. No order by. If I use ResultSet.updateRow to change any column, the CPU consumption of oracle.exe jumps 100x. Here is the code.
    Connection con = DriverManager.getConnection("jdbc:default:connection");
    Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
    ResultSet rs = stmt.executeQuery("select cola,colb from tab");
    while (rs.next()) {
    rs.updateString(1, "qwerd"); // comment out to save 99% of your CPU*
    rs.updateRow();
    rs.close();
    stmt.close();
    con.commit();
    For my test case, against 10,000 rows, removing that one line changes the CPU consumption from roughly 7 CPU seconds to 0.07 CPU seconds. I do mean CPU time - not elapsed time. The CPU measurement come from v$sesstat.value. Task manager confirms oracle.exe using 100% of a cpu for the duration of the call.
    I know that this example can be replaced with a single update statement. It is a gross simplification of a much larger proc, to replicate the problem.
    Help?

    Hi. For each row (when really updated), the DBMS is probably having to re-iterate
    through the table in the same unqualified way your query does, to position itself
    to the row you want to update. This whole thing is extremely inefficient, and I
    understand that you've reduced the issue to the simple example, but this does
    expose the critical fault of the algorithm. It breaks the number-one performance+
    rule for DBMS applications+: Don't move the data. Don't bring whole swaths of
    raw rows one-by-one to the client, just to find what you want to modify. Do the
    work where the data is, in the DBMS, using stored procedures. Build your saw mills
    where the trees are.
    Joe Weinstein

  • UpdateRow problem...

    Hi all,
    It's my first time try using JDBC 2.0 API, here is the problem:
    If I use:
    uprs.last();
    uprs.updateFloat("PRICE", 10.99f);
    uprs.updateRow();
    Ok, It's no problem at all, but when I using:
    uprs.getString(1);
    uprs.last();
    uprs.updateFloat("PRICE", 10.99f);
    uprs.updateRow();
    It throws a exception:
    error in row
    I use a JDBC:ODBC bridge coneect to a Access database.
    Please help me!
    Thanks in advance!

    Have you positioned on a row before calling
    uprs.getString(1);?
    It could help if you find out which code line causes the exception.
    Either spread outputs in your code likeSystem.out.println( "Next: getString(1)" );or put each "suspicious" line in an own try-catch-block.

  • UpdateRow() problem fixed, thanks!

    I got my problem worked out, but had to ditch the UpdateRow() statement to do it. It turns out that I had an indexed view that I'd forgotten about, which was causing problems. I removed all the indexes and the updates sped up dramatically using a standard UPDATE statement. The UpdateRow() statement never improved, though. Oh well, it's doing what it needs to do now. Thanks for your help, BAM

    even though you have found an acceptable work-around I just wanted to throw my two cents in.
    first, are running those update rows inside a transaction? just wondering...
    second, i wonder if it is slow because you are updating a column used in the where. as a guess i wonder if it is requerying the result set on every update...

  • Deploy resulset of PL\SQL function, that returns ANYTABLE%TYPE

    How can deploy resulset of PL\SQL function, that returns ANYTABLE%TYPE in SQL?

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by angelrip:
    Hello everyone,
    I've come through the following problem:
    1.- I created an PL/SQL stored procedure which returns a REF CURSOR element, definition looks like this:
    PACKAGE PKG_LISTADOS AS
    TYPE tuplas IS REF CURSOR;
    /* Procedimientos exportados por el paquete */
    PROCEDURE inicializarModuloListados;
    FUNCTION recaudacionUltimoMes(medioPago DEF_MEDIO_PAGO.MEDIO_PAGO%TYPE)
    RETURN tuplas;
    2.- Now I would like to call the stored procedure and retrieve the PL/SQL cursor as a ResultSet Java Object. The code I wrote is this:
    Connection conn;
    XmlDocument paramDef;
    conn=poolMgr.getConnection str_poolDBConnection);
    try
    CallableStatement cstmt=conn.prepareCall("{?=call PKG_LISTADOS.recaudacionUltimoMes(?)}");
    cstmt.registerOutParameter(1, java.sql.Types.OTHER);
    cstmt.setString(2, "MONEDA");
    cstmt.executeQuery();
    ResultSet rs=(ResultSet)cstmt.getObject(1);
    catch(SQLException sqlE)
    3.- However, I can't make it OK, all the time I get the following error:
    SQL Error(17004), java.sql.SQLException: Non valid column type
    May anyone help me with this, thanks in advance:
    Miguel-Angel<HR></BLOCKQUOTE>
    Do something like the following:
    cstmt = conn.prepareCall("{call customer_proc(?, ?)}");
    //Set the first parameter
    cstmt.setInt(1, 40);
    //Register to get the Cursor parameter back from the procedure
    cstmt.registerOutParameter(2, OracleTypes.CURSOR);
    cstmt.execute();
    ResultSet cursor = ((OracleCallableStatement)cstmt).getCursor(2);
    while(cursor.next())
    System.out.println("CUSTOMER NAME: " + cursor.getString(1));
    System.out.println("CUSTOMER AGE: " + cursor.getInt(2));
    cursor.close();
    null

  • Help on UpdateRow( ) of OAPlsqlEntityImpl

    Hi All,
    I have seeded EO say EO1 which has association with EO2.
    Both EO1 and EO2 are extending OAPlsqlEntityImpl.
    On "Apply" of that page,
    Only EO2 has to be populated, but as there is association between EO1 and EO2,
    EO1 methods are also called.
    In EO1 , UpdateRow( ) is been overridden to call plsql proceedure to insert or update the backend tables (All this is seeded code).
    My question is will this updateRow( ) called for every row ie is the plsql proceedure called for eevry row or is it called with all the set of rows....
    Depending on this i need to write my custom logic.
    Thanks,
    Sushma.

    But interstingly i could see that its been called only once even i have 3 new rows...this i could confirm by looking into the diagnostics...
    public void updateRow()
    OADBTransaction oadbtransaction = getOADBTransaction();
    OracleConnection oracleconnection = (OracleConnection)oadbtransaction.getJdbcConnection();
    CszDiagnoseObjUtil.diagnosePrivateFields(this, oadbtransaction);
    IncidentDBVVORowImpl incidentdbvvorowimpl = getOldIncidentDataInDB(oadbtransaction);
    if(oadbtransaction.isLoggingEnabled(1))
    oadbtransaction.writeDiagnostics(this, "Begin updateRow()", 1);
    i have this diagnostics code written...i could see that only once "Begin updateRow()" getting there...
    I even confirmed the same by...i used user hook to put some insert statements into some temp table....i could see that only the plsql procedure is called....
    So is this a bug...or pls let me know if i am missing something.....

Maybe you are looking for