6:01 AM
0



JDBC is a technology given by sun micro systems for connecting java application with wide range of database in independent manner.It is a technology but not a programming language .
JDBC technology has its own API and specification.

It has 4 types of drivers:

1.JDBC ODBC bridge driver
2.Native API Java driver
3.Net-protocal  driver
4.Native-protocal  driver(thin driver)

steps to develop JDBC application:

1.To load jdbc driver:

In this first step we have to load jdbc driver class.After loading driver class into jvm then internally one static block will be executed.it will create an object.it should be register with DriverManager
service.DriverManager service stores the jdbc class objects.

ex: Class.forName("oracle.jdbc.OracleDriver");

2.Establishing a connection with database:

When a jdbc driver is loaded,then internally its object will be  registerd wirh DriverManager service.If we want to connect with database then we have to communicate with DriverManager service.so we have a class DriverManager in java.sql.* package.In DriverManager we are having a static method getConnection() to obtain a connection with database

ex: Connection con = DriverManager.getConncetion("url","username","password");

 url: jdbc:oracle:thin:@localhost:1521:xe
 here xe is oracle service present in your pc

Program for connecting java application with oracle10g:

import java.sql.*;
import java.util.*;
public class Dbdemo1
{
public static void main(String args[]) throws Exception
{
Class.forName("oracle.jdbc.OracleDriver");
System.out.println("driver loaded");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
System.out.println("connected to oracle10g");
}
}






 










0 comments:

Post a Comment