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());
    }
  }
}

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.

I got it thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.