PDA

Click to See Complete Forum and Search --> : ResultSet objects


HairyDave
Nov 6th, 2002, 09:45 AM
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

CreoN
Nov 9th, 2002, 10:16 AM
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/api/java/sql/ResultSet.html

HairyDave
Nov 9th, 2002, 12:28 PM
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