JDBC: Connection With Oracle Database

For connecting with the Oracle database from JAVA application, you need to follow 5 steps to perform database connectivity. Below are connection information specific to oracle database:

  1. Driver class: The driver class for the oracle database is oracle.jdbc.driver.OracleDriver.
  2. Connection URL: The connection URL for the oracle database is jdbc:oracle:thin:@localhost:1521:FacingIssuesOnITDB here jdbc is the API, oracle is the database, localhost is the server name on which oracle is running, we may also use IP address, 1521 is the port number and FacingIssuesOnITDB is the database name. We may use any database, in such case, you need to replace the FacingIssuesOnITDB with your database name.
  3. Username: The default username for the oracle database is root.
  4. Password: Password is given by the user at the time of installing the oracle database. In this example, we are going to use root as the password.
import java.sql.*;
class OracleConnection{
public static void main(String args[]){
//Step 1: Register the driver class
//Step 2: Create connection with database
   Connection con=DriverManager.getConnection(
//here FacingIssuesOnITDB is database name, root is username and password
//Step 3: Create statement
 Statement stmt=con.createStatement();
//Step 4: Execute query
 ResultSet rs=stmt.executeQuery("select * from emp");   

  System.out.println(rs.getInt(1)+"  "+rs.getString(2)+"  "+rs.getString(3));
//Step 5: close connection
catch(ClassNotFoundException e){
catch(SQLException e){

Here you learn about steps to connect database with application and specific configuration information for Oracle.

See also :

Learn More on JDBC

Follow below links to learn more on JDBC and solving JDBC related issues :

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s