SQLException Data Not Found

Hi everyone,

I am having a problem retrieving data from a SQl Server 2000 database. Below is the code

try {

dbURLStr = "jdbc:odbc:db_gellassoc";

Connection con = DriverManager.getConnection (dbURLStr, "", "");

Statement stmt = con.createStatement();

sqlStr = "Select * from tb_jobclass order by SortOrder;";

ResultSet rs = stmt.executeQuery(sqlStr);

Vector vGroupedListings = new Vector();

String test;

while(rs.next()) {

vJobClasses.addElement(rs.getString("JobClass").trim());

System.out.println(rs.getString("JobClass").trim());

}

catch(SQLException ex) {

System.out.println("SQLException " + ex.toString();

}

On the second call to rs.getString("JobClass"), I get the SQLException data not found. Can you not call getString on the same column twice in the same row?

Is it a problem with the JDBC driver?

I have also written a little Visual Basic program to update and add new records to this database and it works just fine.

Any help would be greatly appreciated.

Thanks in advance,

Greg

[1143 byte] By [gageller] at [2007-9-26 16:50:12]
# 1

Hi,

The problems occurs when you try to read the same column value twice.

You are reading the value first

vJobClasses.addElement(rs.getString("JobClass").trim());

You are trying to read it a second time here:

System.out.println(rs.getString("JobClass").trim());

Here is the error. You should not read the same column twice from a result set. If you want the value to be used many times, save it in a variable and then use that variable.

all the best,

Nish

kaluloo at 2007-7-2 20:47:58 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
this is fairly well known issue and the best answer is the one given above. http://forum.java.sun.com/thread.jsp?forum=48&thread=89901 http://forum.java.sun.com/thread.jsp?forum=48&thread=85793
Guest at 2007-7-2 20:47:58 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
I think it may also depend on the driver you are using. In the above example, I am using the jdbc odbc bridge driver. In another project I am using a type 3 driver, and I am able to make multiple calls to the same column in the same row of the record set.
gageller at 2007-7-2 20:47:58 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
A type 3 driver? I have never actually seen one of those. Which one is it? Maybe something that goes to a Corba server?
jschell at 2007-7-2 20:47:58 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...