Oracle corporation has developed their own driver in java language according to sun micro system specifications. the name of the oracle driver is oracle.jdbc.driver.OracleDriver
Steps to work with Type-4 driver
1. load or register Oracle Driver
Class.forName("oracle.jdbc.driver.OracleDriver");
or
oracle.jdbc.driver.OracleDriver d=new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
or
Driver d=new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
or
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver())
2. when we are using OracleDriver we need to establish the connection with oracle driver with the help of driver manager service.
the url format for establishing the communications with oracle database is
jdbc:oracle:nameoforacledriver:@DSN/IP address:Portno:servicename
Name of OracleDriver is thin
IP address is :@localhost or 127.0.0.1
oracle port number :1521
service name: this we can know by using query in database
class jdbcthin
{
public static void main(String arg[]) throws Exception
{
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("Drivers are loaded");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
System.out.println("Connection is established");
Statement st=con.createStatement();
String s1="insert into emp values(1,'abc','hyd')";
int i=st.executeUpdate(s1);
System.out.println("row is inserted");
con.close();
}
}
Steps to work with Type-4 driver
1. load or register Oracle Driver
Class.forName("oracle.jdbc.driver.OracleDriver");
or
oracle.jdbc.driver.OracleDriver d=new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
or
Driver d=new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
or
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver())
2. when we are using OracleDriver we need to establish the connection with oracle driver with the help of driver manager service.
the url format for establishing the communications with oracle database is
jdbc:oracle:nameoforacledriver:@DSN/IP address:Portno:servicename
Name of OracleDriver is thin
IP address is :@localhost or 127.0.0.1
oracle port number :1521
service name: this we can know by using query in database
select * from global_name
In many systems it will give xe
ex:
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
when we use this driver we need to keep in odbc.jar file in class path
Example Program for Type-4 Driver
import java.sql.*;class jdbcthin
{
public static void main(String arg[]) throws Exception
{
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("Drivers are loaded");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
System.out.println("Connection is established");
Statement st=con.createStatement();
String s1="insert into emp values(1,'abc','hyd')";
int i=st.executeUpdate(s1);
System.out.println("row is inserted");
con.close();
}
}
No comments:
Post a Comment