Results 1 to 2 of 2
  1. #1
    kvikas is offline Member
    Join Date
    Apr 2008
    Posts
    2
    Rep Power
    0

    Default ResultSet.updateRow() problem

    Hi All,
    I'm using MS Access DB. I want to trim the data in the table named 'Sold'. I'm getting correct resultset with all rows from table 'Sold'. When i iterate over resultset and tries to update the column value after trimming, only first row gets updated correctly with trimming. Unexpected results occurred from second row. It fetches empty string or string with characters omitted from right if i places leading spaces to the column value in DB.
    *empName is the only column in the table 'Sold'. Whose type is 'Text'.

    Heres the code,

    public void trimDataRows(){
    ResultSet rs=null;
    int updateCount=0;
    String empNo=null, empName=null, tempName=null, checkedFlag=null;
    try{
    rs=stmt.executeQuery("select * from Sold");

    rs.last();
    int rowCount=rs.getRow(); //Nomber of rows in resultset.
    System.out.println("Count "+rowCount);

    for(int i=1; i<=rowCount; ++i){

    rs.absolute(i);
    empName=rs.getString(1);
    System.out.println("Old: "+rs.getString(1)+"& "+empName.length());
    tempName=empName.trim();
    System.out.println("New: "+tempName+"& "+tempName.length());
    rs.updateString(1, tempName);
    rs.updateRow();
    updateCount++;
    }
    rs.close();
    stmt.close();
    con.close();


    }catch(Exception e){ e.printStackTrace();}
    }

  2. #2
    rico16135 is offline Member
    Join Date
    Apr 2008
    Posts
    28
    Rep Power
    0

    Default

    while(rs.next() ) {
    //stuff todo
    }

    Not clear exactly what your prob is

Similar Threads

  1. problem with ResultSet.updateRow()
    By kvikas in forum New To Java
    Replies: 0
    Last Post: 04-14-2008, 10:00 AM
  2. ResultSet to XML
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-14-2008, 09:50 AM
  3. ResultSet to HTML
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-12-2008, 09:32 AM
  4. ResultSet to JTable
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-11-2008, 09:01 AM
  5. ResultSet example
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-20-2008, 08:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •