Connect Java with Oracle Database


Prev Tutorial Next Tutorial

How to Connect Java Application with Oracle Database

Oracle corporation has provided two Jdbc driver software for connection java application to a database of oracle server.

  • Oracle oci Driver
  • Oracle thin Driver
connect java with oracle

For connecting java application with the oracle database, we need to follow below steps. In this example we are using Oracle 10g as the database. So we need to know following information for the oracle database.

The following are the connection properties of oracle thin driver.

Driver Class: Oracle.Jdbc.OracleDriver
Connection url: jdbc:oracle:thin:@localhost:1521:xe
Username:The default username for the oracle database is system.
passwordPassword is given by the user at the time of installing the oracle database.


  • jdbc is the API
  • oracle is the database
  • thin is the driver
  • localhost is the server name on which oracle is running, we may also use IP address
  • 1521 is the port number and
  • XE is the Oracle service name.

Note: You may get all above information from the tnsnames.ora file.

Create a table in oracle database

create table student(roll number(10),name varchar2(40));  

Example to Connect Java Application with Oracle database

import java.sql.*;  
class OracleCon
public static void main(String args[]){  
//step1 load the driver class  
//step2 create  the connection object  
Connection con=DriverManager.getConnection(  
//step3 create the statement object  
Statement stmt=con.createStatement();  
//step4 execute query  
ResultSet rs=stmt.executeQuery("select * from student");  
System.out.println(rs.getInt(1)+"  "+rs.getString(2)+"  "+rs.getString(3));  
//step5 close the connection object  
catch(Exception e)

Prev Tutorial Next Tutorial


Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: or 9999595223

wifi cctv camera

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements

Buy Websites 9999595223
wifi cctv camera

Wifi CCTV Camera RS:1200 to 2499.

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: or 9999595223 Try this Keyword C++ Programs