Working with a Result Set : JDBC ODBC « Database « Java Tutorial






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

public class ResultSetExample {
  public static void main(String args[]) {
    try {
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

      Connection con = DriverManager.getConnection("jdbc:odbc:Inventory", "", "");

      Statement stmt = con.createStatement();

      ResultSet rs = stmt.executeQuery("SELECT SupplierName,ProductName, Price "
          + "FROM ProductSuppliersView WHERE CategoryName LIKE '%BEVERAGES%' ");
      while (rs.next()) {
        String supplier = rs.getString("SupplierName");
        String product = rs.getString("ProductName");
        int price = rs.getInt("Price");

        System.out.println(supplier + " sells " + product + " for $" + price);
      }

      stmt.close();
      con.close();
    } catch (Exception e) {
      System.out.println(e);
    }
  }
}








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