To use type-4 driver of oracle database we have to set classpath(if we are using normal editor like editplus,notepad++) and we have to import that jar file if we are using
IDE(like Eclipse, NetBeans) of that jar file(ojdbc6.jar) provided by database
vendors(Oracle Corporation) which is available in
C:\oraclexe\app\oracle\product\11.2.0\server\jdbc\lib\ojdbc6.jar.
How to set classpath or import ojdbc6.jar file in our program search in google.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class Jdbc6
{
public static void main(String[] args)
{
// Loading & Register the Type-4 Driver Class(OracleDriver). But this line is optional
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
//We can also use this driver Class.
//Class.forName("oracle.jdbc.OracleDriver")
}
catch(ClassNotFoundException cnfe)
{
cnfe.printStackTrace();
}
// Establishing the connection
// this is try with resources can be applied in jdk1.7 or above version
try(Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1522:xe","system","manager"))
{// port_No='1522' & database_name='xe'/'orcl' , username='system' & password='manager'
// Creating statement to execute query
Statement st=con.createStatement();
// Executing Query
st.executeUpdate("create table emp(id number(3)primary key,name varchar2(10),sal number(4),job varchar2(10))");
System.out.println("Table created");
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
IDE(like Eclipse, NetBeans) of that jar file(ojdbc6.jar) provided by database
vendors(Oracle Corporation) which is available in
C:\oraclexe\app\oracle\product\11.2.0\server\jdbc\lib\ojdbc6.jar.
How to set classpath or import ojdbc6.jar file in our program search in google.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class Jdbc6
{
public static void main(String[] args)
{
// Loading & Register the Type-4 Driver Class(OracleDriver). But this line is optional
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
//We can also use this driver Class.
//Class.forName("oracle.jdbc.OracleDriver")
}
catch(ClassNotFoundException cnfe)
{
cnfe.printStackTrace();
}
// Establishing the connection
// this is try with resources can be applied in jdk1.7 or above version
try(Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1522:xe","system","manager"))
{// port_No='1522' & database_name='xe'/'orcl' , username='system' & password='manager'
// Creating statement to execute query
Statement st=con.createStatement();
// Executing Query
st.executeUpdate("create table emp(id number(3)primary key,name varchar2(10),sal number(4),job varchar2(10))");
System.out.println("Table created");
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
0 Comment to "Jdbc Program to create table 'emp' in oracle database by using type-4 driver."
Post a Comment