Thursday 4 April 2013

How to Connect with Oracle and SQL Server database with Java

JDBC-ODBC Connection is a JDBC driver that translates the operation in  JDBCinto ODBC. For ODBC,it is a normal java application program. This bridge provides JDBC  for database in which an ODBC driver is available like Oracle. The bridge is represented as sun.jdbc.odbc.The Java contain a defined package and its library to access ODBC.
The program should include the sql class also
Loading a driver by making a call class.forName ( ),that accept driver class as argument as :
 Class.forName("oracle.jdbc.driver.OracleDriver"); // This is for oracle connection
Class.forName("com.mysql.jdbc.Driver");          // This is for SQL connection
DriverManager.getConnection ( ) : This provides you to established a connection between url and database as:
DriverManager.getConnection("jdbc:oracle:thin:@IP:1521:ServiceName","UserName","Password"); // This is for oracle connection.
DriverManager.getConnection("jdbc:mysql://localhost:3306/dtu", "root", "");//For SQL Server
A jar file odbc6.jar or odbc14.jar  for Oracles should also be Included.
A jar file sqljdbc.jar for SQL should also be Included.

The Connection object call a close ( ),return you the connection is closed.

No comments:

Post a Comment