Results 1 to 2 of 2
  1. #1
    Shivraj is offline Member
    Join Date
    Mar 2009
    Posts
    13
    Rep Power
    0

    Default Some problem in fetching record

    hi

    this is my code


    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("jdbc:odbc:project ","scott","tiger");
    String s="select siteid from sitedetail1;";
    PreparedStatement stmt=con.prepareStatement(s);

    ResultSet rs=stmt.executeQuery();



    while(rs.next())
    {
    int i;
    for(i=0;rs.next();i++)
    {
    sid.add(""+rs.getInt(1));


    }
    }
    con.close();
    stmt.close();
    }
    catch(Exception e1)
    {
    e1.printStackTrace();
    }

    in this code i have bind database field with combobox
    this code is compile and run but proper results r not given
    all records in perticular field is not fetch in combo box special 1st record is not fetched fetching is starting from second record.
    any logical mistake then please advise me what is correct code

  2. #2
    Irina is offline Member
    Join Date
    Mar 2009
    Posts
    1
    Rep Power
    0

    Default

    hi!
    Your problem is in two loops, that you are using.
    If you write something like this
    while(rs.next())
    {
    sid.add(""+rs.getInt(1));
    }
    you will get all records.

Similar Threads

  1. Fetching sequence
    By Shivraj in forum New To Java
    Replies: 1
    Last Post: 03-19-2009, 03:30 PM
  2. problem with fetching data
    By payal.mitra86 in forum JDBC
    Replies: 0
    Last Post: 05-24-2008, 02:29 PM
  3. Fetching rows from DB
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-06-2008, 10:23 AM
  4. Replies: 2
    Last Post: 11-11-2007, 09:07 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
  •