Query a jdbc odbc connection : JDBC ODBC « Database « Java Tutorial






import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class MainClass{
  public static void main(String[] arguments) {
    String data = "jdbc:odbc:YourSettings";
    try {
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      Connection conn = DriverManager.getConnection(data, "", "");
      Statement st = conn.createStatement();
      ResultSet rec = st.executeQuery("SELECT * FROM Coal WHERE (Country='"
          + arguments[0] + "') ORDER BY Year");
      while (rec.next()) {
        System.out.println(rec.getString(1) + "\t" + rec.getString(2) + "\t\t" + rec.getString(3)
            + "\t" + rec.getString(4));
      }
      st.close();
    } catch (Exception e) {
      System.out.println("Error: " + e.toString() + e.getMessage());
    }
  }
}








20.33.JDBC ODBC
20.33.1.Connect to Access Database using JDBC-ODBC bridge
20.33.2.sun.jdbc.odbc.JdbcOdbcDriver Connection Example
20.33.3.Load JdbcOdbcDriver and create a table
20.33.4.Query a jdbc odbc connection
20.33.5.Get metadata from jdbc:odbc connection
20.33.6.Working with a Result Set
20.33.7.Working with ResultSetMetaData
20.33.8.List tables in a database