I'm trying to load data from a result set into an array, and I need to loop through the data set looking for a particular string in one of the data fields. when I find it, that goes into the new array. I then need to go back to the result set and loop through again, looking for the next value. The ORDER BY function of sql is not able to sort in the way I need, so this is the only way I can think of to do this. I am using JRun as an appserver, with sql server as the database server. When I try to use the java.sql RecordSet.first() function, I get an SQL Exception that says method RecordSet.first not found. It's in the java.sql specs, so why can't I use it? Any suggestions?
-
Move to first record (3 messages)
- Posted by: Nancy Anderson
- Posted on: May 24 2001 08:58 EDT
Threaded Messages (3)
- Move to first record by Andy Nguyen on May 24 2001 10:01 EDT
- Move to first record by Nancy Anderson on May 24 2001 10:26 EDT
- Move to first record by Race Condition on May 24 2001 12:13 EDT
- Move to first record by Nancy Anderson on May 24 2001 10:26 EDT
-
Move to first record[ Go to top ]
- Posted by: Andy Nguyen
- Posted on: May 24 2001 10:01 EDT
- in response to Nancy Anderson
This is from the API docs for the JDK1.3:
"A default ResultSet object is not updatable and has a cursor that moves forward only. Thus, it is possible to iterate through it only once and only from the first row to the last row. New methods in the JDBC 2.0 API make it possible to produce ResultSet objects that are scrollable and/or updatable."
I guess the first thing to check is whether or not your JDBC driver is at least up to 2.0 spec. Then, check to make sure that you're creating a scrollable result set. You should create your statement object, either a regular Statement or a PreparedStatement, with a result set type of either ResultSet.TYPE_SCROLL_SENSITIVIE or ResultSet.TYPE_SCROLL_INSENITIVE.
e.g.
Connection con = ...;
Statement statement = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
Hope this helps,
Andy -
Move to first record[ Go to top ]
- Posted by: Nancy Anderson
- Posted on: May 24 2001 10:26 EDT
- in response to Andy Nguyen
Thanks! -
Move to first record[ Go to top ]
- Posted by: Race Condition
- Posted on: May 24 2001 12:13 EDT
- in response to Nancy Anderson
If that doesn't work you could always use two arrays. Load the first one with all of the data from the ResultSet, then then iterate to your heart's content filling the second array with the stuff you want.