JDBC-Odbc Connection

JDBC-ODBC Connection is a JDBC driver that translates the operation in JDBC into ODBC. For ODBC,it is a normal java application program.

JDBC-Odbc Connection

JDBC-ODBC Connection

     

JDBC-ODBC Connection is a JDBC driver that translates the operation in  JDBC into ODBC. For ODBC,it is a normal java application program. This bridge provides JDBC  for database in which an ODBC driver is available. The bridge is represented as sun.jdbc.odbc.The Java contain a defined package and its library to access ODBC.

Understand with Example

In this Tutorial we help you in explaining JDBC Odbc Connection in Java. The code explains you a how creation and closing of connection is done. For this code we have a   JdbcOdbc Connection class. The class contains a main method, that include a list of steps as follow -

   Loading a driver is the first step to be done inside the try block of main method ( ) by calling a Class.forName ( ),this class accept a "sun.jdbc.odbc.jdbcodbc Driver" as argument.

   DriverManager.getConnection ( ) : This establish or built a connection between url and emp table in the database.

 The print print the "New Connection Create..."..The Connection object call a close ( ),return you the connection is closed. The println show the "Connection closed"

In case the exception exists in a try block, the subsequent catch block check and handle the exception. 

JdbcOdbcConnection.java

import java.sql.*;



public class JdbcOdbcConnection {



  public static void main(String args[]) {



  Connection con = null;





  try {



  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");



  con = DriverManager.getConnection("jdbc:odbc:emp");



  System.out.println("New Connection Create ....");

  con.close();

  System.out.println("Connection closed");



  catch (Exception e) {

  System.out.println(e);

  }



  }

}

  
 

Output

New Connection Create ....
Connection closed

Download code