JDBC Connectivity 1739265918951
JDBC Connectivity 1739265918951
To connect java application with the oracle database, we need to follow 5 following
steps. In this example, we are using Oracle 10g as the database. So we need to know
following information for the oracle database:
Create a Table
Before establishing connection, let's first create a table in oracle database.
Following is the SQL query to create a table.
In this example, we are connecting to an Oracle database and getting data from emp
table. Here, system and oracle are the username and password of the Oracle
database.
import java.sql.*;
class OracleCon{
public static void main(String args[]){
try{
//step1 load the driver class
Class.forName("oracle.jdbc.driver.OracleDriver");
}
}
The above example will fetch all the records of emp table.
To connect java application with the Oracle database ojdbc14.jar file is required
to be loaded.
download the jar file ojdbc14.jar
Two ways to load the jar file:
temporary
permanent
C:>set classpath=c:\folder\ojdbc14.jar;.;
Go to environment variable then click on new tab. In variable name write classpath
and in variable value paste the path to ojdbc14.jar by appending ojdbc14.jar;.; as
C:\oraclexe\app\oracle\product\10.2.0\server\jdbc\lib\ojdbc14.jar;.;