jdbc:odbc bridge : JDBC ODBC : Database SQL JDBC : Java examples (example source code) Organized by topic

Java
C++
PHP


Java  »  Database SQL JDBC   » [  JDBC ODBC  ]  Screenshots 
 



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
























Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.