Problem using updatable ResultSet

I am using scrollable and updatable result sets to query and modify data. The problem I am having is that when I make a change to the data in a field on my form, the data gets modified in the database and not in the result set in my form. This only occurs when the field(column) I try to modify is one of the fields(columns) that I use in my query criteria. For example, I can issue the query "SELECT id, fname, lname FROM user WHERE fname='TED'". The problem is, if I change fname from 'TED' to 'JOE' from one of the records in the result set on my form, it gets changed in the database but NOT in the result set. If I change the field lname, the change is made in the result set and the database with no problem.
I have also tried to issue this statement but it does not help:
resultSet.refreshRow();
This is the basic code for the update:
private void updateRecord() {
try {
resultSet.updateString("id",idField.getText());
resultSet.updateString("fname",fnameField.getText());
resultSet.updateString("lname",lnameField.getText());
resultSet.updateRow();
} catch( SQLException ex ) { //Trap SQL errors
JOptionPane.showMessageDialog(textPane,
"Error updating the database"+'\n'+ex.toString());
Any help would be appreciated.

has been moved to JDBC forum...

Similar Messages

  • Using updatable ResultSet to update Unicode data ?

    Is it possible to use Unicode data in updateString() methods for updatable resultset ? Or I only can do it using OraclePreparedStatement ? I've opened an updatable ResultSet and trying to update NCHAR column using the code below:
    rset.updateString(6, "\uFF23\uFF23");
    which fails with "java.sql.SQLException: Cannot map Unicode to Oracle character".
    An attempt to do the same thing with regulair English data
    rset.updateString(6, "CC");
    causes "java.sql.SQLException: ORA-12704: character set mismatch" on insertRow(). The server primary encoding is UTF8 and I have AMERICAN_AMERICA.UTF8 in NLS_LANG in the registry. I would really appreciate any help on this ...

    Thanks ! I guess I was looking in the wrong jdbc directory (the one that comes with JDev) ...

  • DataBase problem, when update ResultSet

    Hi,
    I use mysql drivers and the problem is:
    i create a connection and then a statement with option CONCUR_UPDATABLE.
    Calling stmt.getResulSetConcurrency(), the answer is CONCUR_UPDATABLE,
    but if i execute a query, calling rs.getConcurrency() the answer is CONCUR_READ_ONLY!!
    note: rs is the ResultSet return by the query.
    In short: I can't update database throught ResultSet object!
    And I have the permission to do!
    Why?
    thank you for answer.
    Luca

    Just because you request updateable resultsets doesn't mean the driver supports it. I don't know if MySQL supports it or not. If it does, then I'd have to guess that your particular query is done in such a way as to not be updateable. I believe if your query does a join, for example, it can't be updateable.

  • Problem using UPDATE command from Java

    I am getting an error when I use the following code in my java file and use it in JSP through beans:
         sql = " UPDATE SHOPPINGCART SET QUANTITY='"+quant+"' WHERE USERNAME ='"+username"' AND TOYID='"+toyid+"' ";
         CM.executeUpdate(sql); //CM is the connection object and I have a method which inturn calls executeUpdate
    This is the error
    C:\Program Files\Apache Software Foundation\Tomcat 4.1\webapps\DBTest\WEB-INF\cl
    asses\user>javac *.java
    ToyDBAO.java:124: ';' expected
    +"WHERE USERNAME ='"+username"' AND TOYID='"+toyid+"' ";
    ^
    ToyDBAO.java:124: not a statement
    +"WHERE USERNAME ='"+username"' AND TOYID='"+toyid+"' ";
    ^
    2 errors
    Please reply
    Message was edited by:
    aniketh_parmar

    Now the prob is that its compiling the java file. But when I run the program, an error is caught
    sql = " UPDATE SHOPPINGCART SET QUANTITY='"+quant+"' (WHERE USERNAME ='"+username+"' AND TOYID='"+toyid+"')";
    This is the error in tomcat window
    Message Error:You have an error in your SQL syntax; check the manual that corres
    ponds to your MySQL server version for the right syntax to use near '(WHERE USER
    NAME ='aniketh_parmar' AND TOYID='3')' at line 1

  • Problem with updating oracle DB with java date thru resultset.updateDate()

    URGENT Please
    I am facing problem in updating oracle database with java date through resultset.updateDate() method. Can anybody help me please
    following code is saving wrong date value (dec 4, 2006 instead of java date jul 4, 2007) in database:
    ResultSet rs = stmt.executeQuery("SELECT myDate FROM myTable");
    rs.first();
    SimpleDateFormat sqlFormat = new SimpleDateFormat("yyyy-mm-dd");
    java.util.Date myDate = new Date();
    rs.updateDate("myDate", java.sql.Date.valueOf(sqlFormat.format(myDate)));
    rs.updateRow();

    I believe you should use yyyy-MM-dd instead of yyyy-mm-dd. I think MM stands for month while mm stands for minute as per
    http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html
    (If this works, after spending so much of your time trying to solve it, don't hit yourself in the head too hard. I find running out of the room laughing hysterically feels better).
    Here is a more standard(?) way of updating:
    String sqlStatement=
    "update myTable set myDate=? where personID=?"
    PreparedStatement p1= connection.prepareStatement(sqlStatement);
    p1.setDate(1,new java.sqlDate());
    p1.setInt(2, personID);
    p1.executeUpdate();

  • Problem to get ResultSet when it is used a Date type in the query condition

    hello ,
    I having a bit of nightmare getting a ResultSet how result of one simple Query for a table when the condition WHERE involve a Date type.
    To change the String value in a date to use in the query condition, I tried both:
    String strDate = "dd/mm/yyyy";
    (1.) java.sql.Date sqlDate = new java.sql.Date(strDate.getTime() )
    (2.) SimpleDateFormat formatter = new SimpleDateFormat(strDate) ; sqlDate = formatter.parse(strDate);
    and finally I use this code to get the ResultSet:
    sql = "SELECT * FROM myTable Where (idCli = " + cd_Cli + " And dateReg = " + sqlDate + ")";
    statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
    resultSet = statement.executeQuery(sql);
    boolean ok = resultSet.last();
    totNumberOfRegistration = resultSet.getRow();
    But In both the cases I get a empty resultSet.
    I shoul like if someone would look my code to say me where it is the mistake...
    thank you
    tonyMrsangelo
    P.S. I tryed using PrepareStatement too to get the ResultSet, but in that case I couldn't use the ResultSet because executing the statement resultSet.last() I get the error: "Result set type is TYPE_FORWARD_ONLY"

    In a database like Oracle, you need to use a function like TO_DATE; other databases may have something similar.
    However, the proper way to do this is to use a PreparedStatement. Then you can say
    PreparedStatement ps = conn.prepareStatement("update SOMETABLE set SOME_DATE=? where SOME_ID=?");
    ps.setDate(1, new java.sql.Date(someJavaUtilDate.getTime()));
    ps.setInt(2, theId);
    ps.executeUpdate();

  • Problem in Update statement using Execute Immediate

    Hi All,
    I am facing problem in update statement.
    I am creating dynamic sql and use "execute immediate" statement to execute a update statement.
    But it is not updating any thing there in the table.
    I have created a query like :
    update_query='Update '|| Table_Name ||' t set t.process_status =''Y'' where t.tid=:A';
    Execute immediate update_query using V_Id;
    commit;
    But it is not updating the table.
    I have a question , is execute immediate only does insert and delete?
    Thanks
    Ashok

    SQL> select * from t;
                     TID P
                     101 N
    SQL> declare
      2     V_Id          number := 101;
      3     Table_Name    varchar2(30) := 'T';
      4     update_query  varchar2(1000);
      5  begin
      6     update_query := 'Update '|| Table_Name ||' t set t.process_status =''Y'' where t.tid=:A';
      7     Execute immediate update_query using V_Id;
      8     commit;
      9  end;
    10  /
    PL/SQL procedure successfully completed.
    SQL> select * from t;
                     TID P
                     101 Y                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • HT201210 nowadays have many user have problem with update to ios7 and need active with apple id maybe in the future in order escape from these problems must be stop use these products else. Because of simple user don't know about this technology and somet

    nowadays have many user have problem with update to ios7 and need active with apple id maybe in the future in order escape from these problems must be stop use these products else. Because of simple user don't know about this technology and sometime just hear from other user that it 's difficult to use then force they change phone that use to handle to another.

    It is a feature to discourage the theft of iPhones by making them useless if resold. It's not going anywhere. It's simple: just don't buy a phone until you make sure that the activation lock has been disabled.

  • Problem to update UDO-recordsets using a matrix with DBDataSource

    Hello,
    I've got a problem with updating recordsets in an UDO-Table using DBDataSource.SetValue().
    Special szenario: I use a matrix bounded with DBDataSources. Adding new records and loading them via DBDataSource.Query() with conditions works fine. The UDO object type is "Document" without lines.
    In the simple way now I load just one record and after this I was trying to set an "message" to an simple, editable edittext-column via calling:
    oDBDataSource.SetValue("U_Message", 0, "Hello world");
    oMatrix.LoadFromDataSource();
    Now it's visible in the matrix.
    But when I call update via clicking the update-button, B1 do say, everything was ok (green status-message). Reloading this recordset you can see: it was not stored in the database
    Even not after:
    oMatrix.FlushToDataSource();
    As a workaround I do write the "message" via using Cell.Specific.
    Can anybody help me?
    I'am using SBO 2005 A SP 01 PL 39
    Edited by: Christian Bührig on Mar 18, 2008 4:48 PM

    look at
    New Row in Matrix is a Duplicate and Cannot update Object with new Row
    the next way is do it with recordset and directly insert to table.
    hope it helps
    Petr

  • Hi I am using MAC OS Yosemite10.10.3 and I have a problem to update my photoshopCC cause of error U43M1D204 eventhough I have deleted AAm Updater/1.0/ but It still not worked.  How can I fix it.

    Hi, I am using MAc OS 10.10.3 and I have a problem to update my photoshopCC because of error U43M1D204.  I have deleted AAm Updater/1.0/ but it still not worked.  How can I fix it please help.

    I too have only recently encountered this problem. I have been able to burn disks before but it keeps making all these weird sounds. It might be a hardware problem but the fact that everything else that uses a disk works I doubt it.

  • The new ibook app and ibook update is designed for iPhone 5 operating system.   When my iPhone4 recently updated the ibook app, it created many problems using the ibook to download and read my books.    Can I get the previous ibook app back on my phone.

    The new ibook app and ibook update is designed for iPhone 5 operating system.   When my iPhone4 recently updated the ibook app, it created many problems using the ibook to download and read my books.    Can I get the previous ibook app back on my phone.

    Check your trash can on the desktop. The old version is automatically moved to the trashcan. You should be able to move it from the trashcan back to the Apps folder within the iTunes folder. The update that was pushed out was for iBooks to work with iOS 7 not iPhone 5. iOS 7 was released today.

  • Problem in update statment when using where condtion

    Hi ,
          Iam using update statment to update field in Z-Table .My statment is not working fine as per my requirement.The statment is as below,
    UPDATE ZFINAL_DATA  SET ZDATE_FLAG = SPACE where ZGLOBAL_CODE ( SELECT LIFNR FROM LFA1 WHERE KTOKK = 'ZLIE' ).
    But this statment is doing my purpose .
    My requirement is , I need to update ZDATE_FLAG = SPACE in ZFINAL_DATA table when LFA1 -LIFNR = ZFINAL_DATA-ZGLOBAL_CODE and LFA1-KTOKK = 'ZLIE'.
    Can any correct the update statment which will be helpfull to proceed further .
    Regards,
    Sriram

    Hi Sriram,
    Have a look into the logic of the below query. Maybe this will fulfil the requirement.
    TYPES:     BEGIN OF lt_lifnr,
             lifnr TYPE lifnr,
         END OF lt_lifnr.
    DATA:      la_lifnr TYPE TABLE OF lt_lifnr,
           wa_zfinal_data TYPE zfinal_data,
           la_zfinal_data TYPE TABLE OF zfinal_data.
    TABLES: zfinal_data.
    SELECT lifnr
    FROM lfa1
    INTO TABLE la_lifnr
    WHERE ktokk = 'ZLIE'.
    SORT la_lifnr BY lifnr.
    SELECT *
    FROM zfinal_data
    INTO TABLE la_zfinal_data.
    LOOP AT la_zfinal_data INTO wa_zfinal_data.
      READ TABLE la_lifnr WITH KEY lifnr = wa_zfinal_data-zglobal_code
                          BINARY SEARCH TRANSPORTING NO FIELDS.
      IF sy-subrc = 0.
        wa_zfinal_data-zdate_flag = space.
        MODIFY la_zfinal_data
        FROM wa_zfinal_data
        INDEX sy-tabix
        TRANSPORTING zdate_flag.
      ENDIF.
    ENDLOOP.
    MODIFY zfinal_data FROM TABLE la_zfinal_data.
    COMMIT WORK.

  • Problem using CLOB in JDBC (NewLOBAPISample)

    I've just tried to run the JDBC NewLOBAPISample, and everything works fine until I try to insert or update on the CLOB column using any characters other than base ASCII. For example, if I attempt to insert the String "$100", it works just fine, but "£100" results in:
    java.sql.SQLException: No more data to read from socket
    I've experimented with this issue with a much smaller test case of my own, and I've been able to narrow down the problem, as I've outlined below. In all cases, PreparedStatement is used for executing.
    Let's say we have a table named "Test" with one CLOB column named "text".
    The original "official" API for inserting a CLOB using the latest 1.4 JDBC Oracle thin driver is:
    // first insert an "empty CLOB"
    PreparedStatement ps;
    ps = con.prepareStatement("INSERT INTO Test (text) VALUES (empty_clob())");
    ps.executeUpdate();
    // then select the empty CLOB
    con.setAutoCommit(false);
    ps = con.prepareStatement("SELECT text FROM Test FOR UPDATE");
    ResultSet rs = ps.executeQuery();
    rs.next();
    CLOB clob = ((OracleResultSet)rs).getCLOB(1);
    // now write to the CLOB
    Writer out = clob.getCharacterOutputStream();
    out.write(myLongText);
    out.close();
    // we're done
    connection.commit();
    The method that is advertised in NewLOBAPISample, and which I've also seen on the Java Developer Forum, is outlined here:
    // first, create statement to insert
    PreparedStatement ps;
    ps = con.prepareStatement("INSERT INTO Test (text) VALUES (?)");
    // create a temporary CLOB and write to it
    CLOB clob = CLOB.createTemporary(con, true, CLOB.DURATION_SESSION);
    Writer out = clob.getCharacterOutputStream();
    out.write(myLongText);
    // set the CLOB on the PreparedStatement and execute
    ps.setClob(1, clob);
    ps.executeUpdate();
    Now, in the above two cases, if "myLongText" has any characters in it besides standard alpha-numerics, the latter approach will fail, although the former (original) approach will still work. In my case, I need to save Danish characters in the CLOB data. (I can't type these characters in this message, as for some reason they are being converted to "æ å ø" during posting, instead of the letters I've typed on my keyboard.)
    Here is a stack trace when I try the createTemporary approach with a short String that contains one or more non-standard characters:
    java.io.IOException: No more data to read from socket
         at oracle.jdbc.dbaccess.DBError.SQLToIOException(DBError.java:716)
         at oracle.jdbc.driver.OracleClobWriter.flushBuffer(OracleClobWriter.java:270)
         at oracle.jdbc.driver.OracleClobWriter.close(OracleClobWriter.java:232)
    Here's the strack trace when the insert String contains only ONE character that is non-standard:
    java.sql.SQLException: No more data to read from socket
         at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
         at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
         at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:1160)
         at oracle.jdbc.ttc7.MAREngine.unmarshalUB1(MAREngine.java:963)
         at oracle.jdbc.ttc7.MAREngine.unmarshalSB1(MAREngine.java:893)
         at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:369)
         at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
         at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
         at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2047)
         at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1940)
         at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2709)
         at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
    Any help with this would be MUCH appreciated.
    Thanks,
    David Karlton

    hi David,
    i tried inserting non-alphanumeric chars but still it goes thru fine.
    here is what i did,
    create table testlob ( id number(5),lobcol clob);
    LobInJava.java
    import java.sql.*;
    import oracle.jdbc.*;
    import oracle.sql.*;
    class LobInJava
    public static void main(String args[]) throws Exception
    DriverManager.registerDriver(new
    oracle.jdbc.driver.OracleDriver());
    Connection conn = DriverManager.getConnection
    ("jdbc:oracle:thin:@host:1522:ora9idb", "scott", "tiger");
    StringBuffer myLongText = new StringBuffer("nm{H$ñVmZ".length() * 10 );
    for(int i=0 ;i < 1000 ;i++ )
    myLongText.append("nm{H$ñVmZ");
    System.out.println( myLongText.length());
    PreparedStatement ps;
    ps = conn.prepareStatement("INSERT INTO Testlob (id,lobcol) VALUES (2,empty_clob())");
    ps.executeUpdate();
    // then select the empty CLOB
    conn.setAutoCommit(false);
    ps = conn.prepareStatement("SELECT lobcol FROM Testlob where id=2 FOR UPDATE");
    ResultSet rs = ps.executeQuery();
    rs.next();
    CLOB clob = ((OracleResultSet)rs).getCLOB(1);
    // now write to the CLOB
    java.io.Writer out = clob.getCharacterOutputStream();
    out.write(myLongText.toString());
    out.close();
    // we're done
    conn.commit();
    ps.close();
    // first, create statement to insert
    PreparedStatement ps;
    ps = conn.prepareStatement("INSERT INTO Testlob (id,lobcol) VALUES (1,?)");
    // create a temporary CLOB and write to it
    CLOB clob = CLOB.createTemporary(conn, true, CLOB.DURATION_SESSION);
    java.io.Writer out = clob.getCharacterOutputStream();
    out.write(myLongText.toString());
    out.close();
    // set the CLOB on the PreparedStatement and execute
    ps.setClob(1, clob);
    ps.executeUpdate();
    ps.close();
    conn.close();
    i am using jdk 1.3 and Oracle9i v9.0.1
    Regards
    Elango.

  • Problem in Updating CLOB data

    Hi,
    I am trying to update a table in oracle using a java application.
    The field i am trying to update is of CLOB type.
    I am calling the following function to updated the table.
    I am reading a data from the a file.
    But i am getting following error
    Exception :java.sql.SQLException: ORA-01002: fetch out of sequence
    Can anybody suggest some modification to make it work.
    Thank You
    public static void InsertClob(DBConnection dbcon,String gene_id){
    try{
    Statement stat = dbcon.con.createStatement();
    String query = "select aaseq,ntseq from gene where gene_id = '"+gene_id.trim()+"' for update ";
    ResultSet rs = stat.executeQuery(query);
    rs.next();
    Clob clob = rs.getClob(1);
    Writer clobWriter = ((CLOB)clob).getCharacterOutputStream();
    File seq = new File("seq.txt");
    FileReader fr = new FileReader(seq);
    char[] cbuffer = new char[10* 1024];
    int nread = 0 ;
    while((nread = fr.read(cbuffer)) != -1)
    clobWriter.write(cbuffer,0,nread);
    fr.close();
    clobWriter.close();
    rs.close();
    stat.close();
    }catch(Exception e){
    System.out.println("Exception :"+e);
    }//End of fucntion

    same problem. Did you solve that? If you leave off the FOR UPDATE, you get "row not locked" when do thhe clobWriter.write(...

  • How to use one ResultSet many times in a jsp page ?

    Hi all,
    I have .jsp page and I have used it to get data from DB and display them to users. So I have to get data from DB in number of places in this particular jsp.
    I thought that it is better to have one ResultSet for entire page and once it is done its job, the ResultSet will be closed and I can use it again and again like this.
    Resultset rs = new ResultSet();
    try{
        //My operations
    }catch(Exception ex){
       //Handle Exceptions
    }finally{
       rs.close();
    }After above code snippet I can use same ResultSet again below the page.
    I just want to know this,
    1. is this a good coding practice?
    2. Should i put rs = null; within finally clause?
    any help will be appreciated
    thank in advance,
    Dilan.

    Ok, Finally I switched my coding to use DAO and DTO, and I learned it through internet.
    I removed all of data access codes from my jsp file(lets say 'functions.jsp'). I then created one interface and two clasess.
    here is my DAO interface.
    public interface UserFunctionsDAO{
        public List<UserFunctionsDTO> selectUserList();
    }here is DTO class
    public class UserFunctionsDTO{
        private String category = "";
        private String sub_category = "";
        private int cat_id = 0;
        private int sub_cat_id = 0;
        public UserFunctionsDTO(){}
        public UserFunctionsDTO(String category, String sub_category, int cat_id, int sub_cat_id){
            this.category = category;
            this.sub_category = sub_category;
            this.cat_id = cat_id;
            this.sub_cat_id = sub_cat_id;
        //Setters and getters will go here.
    }my concrete data access class is like this.
    public class UserFunctionsDataAccess implements UserFunctionsDAO{
        MyDB dbObject = null;
       private static final String SQL_GET_DISTINCT_CAT= "SELECT DISTINCT cat FROM cat_table";
       public List<UserFunctionsDTO> selectUserList(){
           dbObject = new MyDB();
           dbObject.sqlSelect(SQL_GET_DISTINCT_CAT);
           ResultSet rs = dbObject.getResultSet();
           ArrayList list = new ArrayList();
           while(rs.next()){
               list.add(new UserFunctionsDTO(rs.getString('category'), .......................));
           return list;     
    }I think now im following good coding practices, but I have one problem.
    1. How do I retrieve this userlist from my jsp page?
    2. Should I include UserFunctionsDTO in my jsp page as a bean?
    3. If I include it, how can I get the list from it?
    thanks in advance,
    Dilan.

Maybe you are looking for

  • 10.5.7 Fundamental Incompatibility with Mac Pro - Screen/System Lock ups

    Hi all. It looks like 10.5.7 is causing a lot of problems, but I think I found a problem that is very fundamental. First, my system. It's one of the original Mac Pros with Quad Xeons at 2.66GHz. It has 24GB of RAM and several drives in there. I have

  • Drop down in a PDF form

    Hi forum, I'm usign a BADI in ABAP to fill a PDF form.Is there a way you can create a dynamic drop down list in  your form dynamically with values you read from the dictionary table? Thanks Zola

  • DIMP - Two materials in same Production Order

    Hello experts anyone knows if it is possible combine two materials in one production orders with DIMP component? The scenario is for print flexible packaging, in one flexo printing machine we can print 2 different product with similar structure and c

  • File Upload weblogic 8.1 Struts 1.1

    I am getting this error while file uploading in struts Could not deserialize session data CommonsMultipartRequestHandler I read this bug is solved in struts 1.1 i am working on weblogic 81. with struts 1.1 Can anybody help Thanks Shail <Jul 17, 2004

  • Af:tree selected item

    I want to display the selected item from a tree (and to store this into a variable). I tried with selection_listener, but I don't know exactly what to write in the bean. The disclosed_row_keys is used to expand all nodes. <af:tree value="#{bindings.C