cant get a column's value twice

R

Rizwan

whenever I try to read a column's value of a resultset twice, java gives me
an error message :

java.sql.SQLException: Invalid Descriptor Index

In my program, I have to read some column's values more than once. Is there
any way I can do that?



Thanks



// cx is the Connection object
Statement stmt = cx.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY );
String query = "SELECT company_id, batch_id FROM timecard";
ResultSet rs = stmt.executeQuery( query );
String compVal = "";

rs.next();
compVal = rs.getString( "company_id" );
....
readWholeRecord (ResultSet rs);



public void readWholeRecord( ResultSet rs ){
String compV = rs.getString( "company_id" );
...
}
 
S

Sudsy

Rizwan said:
whenever I try to read a column's value of a resultset twice, java gives me
an error message :

java.sql.SQLException: Invalid Descriptor Index

In my program, I have to read some column's values more than once. Is there
any way I can do that?

From the javadocs for ResultSet:

For maximum portability, result set columns within each row should be
read in left-to-right order, and each column should be read only once.

The docs should always be your first point of reference. While it
doesn't say so explicitly, ven-duhs could choose to implement their
driver in such a way that sequential access ONLY is permitted.
Why would you need to read a value more than once anyway? Stick it
in a variable and refer to it to you heart's content.
 
M

marcus

Rizwan
Sudsy gave good advice -- but I wanted to add something.
you are a) getting some records, b) looking at a field, (presumably c)
making a decision on the information in that field -- compVal meaning
compare value?), and d) processing the entire record. Any decision
making should be done in the query IMHO. Try adding a "where
company_id=\"+compVal+"\";" I am not a database expert by any stretch,
but it is much quicker and easier to get the records you need than get
them all and sort through what you need.
-- clh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top