Results 1 to 9 of 9
  1. #1
    flaquitqm is offline Member
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Default Problem with ResultSet

    Hello everybody:
    I have a problem with a result set too. ResultSet doesn't get all data store in my table, the cursor start in the third row, so I miss rows 1 and 2. How can I put the cursor in the first row in a TYPE_FORWARD_ONLY result set? Here is my code:

    TDepartamento dpto = new TDepartamento();
    ArrayList<TDepartamento> listaDptos = new ArrayList<TDepartamento>();
    try {
    sql = "Select * from Departamento order by idDpto";
    statement = TConexion.getConexion().prepareStatement(sql);

    ResultSet rs = statement.executeQuery();
    while (rs.next()){
    dpto.setCodigo(rs.getInt("CodigoDpto"));
    dpto.setDpto(rs.getString("Dpto"));
    listaDptos.add(dpto);
    }


    return listaDptos;
    }

    sorry for my english and thank you

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    6

    Default

    I don't see how this would cause the result to start off on not the first row.

    Only idea is if you are not closing the statement, maybe your custom data accessor is reusing the same open connection, and if it has a reference to the statement in some kind of not threadsafe manner,then maybe the same result set is being read by more than one client at once ?

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default

    Even so, unless that's some sort of non=standard result set there is no way that code there will skip lines (and I wish you'd put a link to this post in the other one you hijacked).

  4. #4
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    842
    Rep Power
    6

    Default

    As per the code you put,its not a scrollable ResultSet.There is no chance as you mentioned record got missed.By default cursor will point before first row and go on travese till the end.

    My doubt is whether any where checking sake have u put "rs.next()"? Once if u use rs.next(),then there is a chance that traversal as happened already...just post your complete code.
    Ramya:cool:

  5. #5
    flaquitqm is offline Member
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Default

    Thanks to all of you for help me. Here is the complete code:

    public ArrayList<TDepartamento> GetDepartamentos() throws SQLException{

    ArrayList<TDepartamento> listaDptos = new ArrayList<TDepartamento>();
    try {
    sql = "Select * from Departamento";

    PreparedStatement statement = TConexion.getConexion().prepareStatement(sql);

    ResultSet rs = statement.executeQuery();

    while (rs.next()){
    int t = rs.getRow();
    TDepartamento dpto = new TDepartamento();

    dpto.setCodigo(rs.getInt("CodigoDpto"));
    dpto.setId(rs.getInt("IdDpto"));
    dpto.setDpto(rs.getString("Dpto"));

    listaDptos.add(dpto);
    }

    return listaDptos;


    } catch (Exception e) {
    // TODO: handle exception
    return listaDptos;
    }
    }

    I have the same problem with other resultset in other procedure.
    when I execute the sql code directly in my database I get row, son the sql statement is ok, but my resultset doesn't have that row and I get an exception.

  6. #6
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    6

    Default

    .. ok, what is the exception.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default

    Are you really eating all Exceptions there?
    That's not good.

  8. #8
    flaquitqm is offline Member
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Default

    The exception tells me that resultset is close. Now everything is working, I didn't get that exception, but I don't know why it was happening.

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default

    I didn't understand any of that, sorry.

    What does your code look like now, and what problems/errors/exceptions are you getting, and where?

Similar Threads

  1. Replies: 4
    Last Post: 04-01-2009, 03:03 AM
  2. Replies: 0
    Last Post: 01-07-2009, 12:44 PM
  3. ResultSet.updateRow() problem
    By kvikas in forum Advanced Java
    Replies: 1
    Last Post: 04-22-2008, 04:11 AM
  4. problem with ResultSet.updateRow()
    By kvikas in forum New To Java
    Replies: 0
    Last Post: 04-14-2008, 11:00 AM
  5. ResultSet example
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-20-2008, 09: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
  •