0

somebody please tell me why im not getting String(X) value as ID,Name,FName are being printed on console correctly but the name of ID(4) from my DB_table is not going into string(X);

package gym.resources.busyicons;
import java.sql.*;
class OdbcAccessQuery {
  public static void main(String [] args) {
    Connection con = null;
    try {
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      con = DriverManager.getConnection("jdbc:odbc:WWFDB");
      Statement sta = con.createStatement();

// getting the data back
      ResultSet res = sta.executeQuery(
        "SELECT * FROM WWFTABLE WHERE ID=4");

      while (res.next()) {
         System.out.println(
           "  "+res.getInt("ID")
           + ", "+res.getString("NAME")
           + ", "+res.getString("FNAME"));
         
         [B]String x = res.getString("NAME");
         System.out.println("x="+x);[/B]
         
      }
      res.close();

      sta.close();
      con.close();
    } catch (Exception e) {
      System.err.println("Exception: "+e.getMessage());
    }
  }
}
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by warbird43
0

I ran into this before with the jdbc-odbc bridge and Access. You can only read from each field of the current row one time. If you try to read it again it throws an exception. I have no idea why and it's irritating. So if you need to capture that value, do that on the first read.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.