Results 1 to 3 of 3

Thread: ResultSet objects

  1. #1

    Thread Starter
    Addicted Member HairyDave's Avatar
    Join Date
    Aug 2002
    Location
    Er...I can't remember.
    Posts
    196

    ResultSet objects

    I am using SQL Server 2000 to implement a database. My Java code needs to access elements of this database. However, I have a problem.

    Each row contains say 8 columns. I may want to access column 1, then column 2 etc etc. However, I may want to access column 6, then column 7 then column 5. This is not allowed through the common Java ResultSet and Statement objects - does anyone know how to do it?

    Thanks

    HD

  2. #2
    Lively Member
    Join Date
    Mar 2001
    Location
    Sweden
    Posts
    115
    If you know the names of the columns (which I assume you do) you could use the different methods in the ResultSet-class like:
    getString(String columnName)
    getDouble(String columnName)
    getInt(String columnName)
    and so on. Well, look for yourself at
    http://java.sun.com/j2se/1.4/docs/ap...ResultSet.html

  3. #3

    Thread Starter
    Addicted Member HairyDave's Avatar
    Join Date
    Aug 2002
    Location
    Er...I can't remember.
    Posts
    196
    No. The problem is that the ResultSet seems to operate a sort of 1 way pass through the row of data.

    If I want to access the 5th column then the 6th then the 3rd, it wont allow you to access the 3rd after you've got the 5th and 6th. That is the problem.

    I always use the getString, Int etc. methods of the ResultSet - it looks very bad in the code if you're using column numbers.

    HD

Posting Permissions

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



Click Here to Expand Forum to Full Width