jdbc:odbc bridge : JDBC ODBC « Database SQL JDBC « Java






jdbc:odbc bridge

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

public class MainClass {
  public static Connection getConnection() throws Exception {
    String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
    String url = "jdbc:odbc:northwind";
    String username = "";
    String password = "";
    Class.forName(driver); // load JDBC-ODBC driver
    return DriverManager.getConnection(url, username, password);
  }

  public static void main(String args[]) {
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    try {
      conn = getConnection();
      stmt = conn.createStatement();
      String query = "select EmployeeID, LastName, FirstName from Employees";
      rs = stmt.executeQuery(query);
      while (rs.next()) {
        System.out.println(rs.getString("EmployeeID") + " " + rs.getString("LastName") + " "
            + rs.getString("FirstName"));
      }
    } catch (Exception e) {
      // handle the exception
      e.printStackTrace();
      System.err.println(e.getMessage());
    } finally {
      try {
        rs.close();
        stmt.close();
        conn.close();
      } catch (Exception ee) {
        ee.printStackTrace();
      }
    }
  }
}
           
         
  








Related examples in the same category

1.JdbcOdbc Connect
2.jdbc odbc bridge connection string
3.Simple example of JDBC-ODBC functionality
4.Using a PreparedStatement through sun.jdbc.odbc.JdbcOdbcDriver
5.Creating and using a stored procedure with sun.jdbc.odbc.JdbcOdbcDriver
6.Retrieving a ResultSet from JdbcOdbcDriver
7.Getting an output parameter from a stored procedure
8.Opening an updatable ResultSet
9.Using ResultSetMetaData from jdbc:odbc
10.Creating a table using JdbcOdbcDriver
11.Using INSERT with JdbcOdbcDriver
12.Using UPDATE with JdbcOdbcDriver
13.Creating and dropping indexes
14.Using DSN-less connection