How can i connect oracle database from java program ? explain the steps with one example?

Questions by vengal79

Showing Answers 1 - 9 of 9 Answers


  • Aug 19th, 2006

Connection con = DriverManager.getConnection("dburl", "id", "password");

  Was this answer useful?  Yes


  • Aug 20th, 2006

Steps to follow in creation of JDBC program-

import java.sql.*;

public class driver1 {

public static void main() throws SQLException,ClassNotFoundException {

Connection con=null;

try {



Statement stmt=con.CreateStatement();

Resultset rs=stmt.executeQuery("Select * from EMP");

while( {




int i=stmt.executeUpdate("update EMP set sal=sal+100 where eno='101' ");

System.out.println(i +"rows updated");




Class.forName ("oracld.jdbc.driver.OracleDriver");

Connection con = DriverManager.getConnection ("jdbc:oracle:thin@localhose:1521:xe","scott","tiger");

xe is for oracle 10g

orcl is for oralce 8i and 9i

  Was this answer useful?  Yes


  • Oct 26th, 2006

Hi friends,Class.forName("oracle:jdbc:driver.OracleDriver");Connection c=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:myoracle","scott","tiger");scott-usernametiger-passwordmyoracle-SID nameSid name we are giving at the time of oracle install.In oracle 8i we can convert into classes111.jar and put at server lib in tomcat.In oracle 9i we can convert into classes12.jar and put at server lib in tomcat.

  Was this answer useful?  Yes

Raghuram Edadala

  • Nov 24th, 2006

import;import java.sql.DriverManager;import java.sql.Connection;import java.sql.Statement;import java.sql.SQLException;public class CRUDOperations{ public static void main(String raghu[])throws SQLException { Connection con=null; try { DataInputStream dis=new DataInputStream(; Class.forName("oracle.jdbc.driver.OracleDriver"); con=DriverManager.getConnection("dburl","user","pswd"); Statement st=con.createStatement(); System.out.println("Enter the Employ id : "); int id=Integer.parseInt(dis.readLine()); System.out.println("Enter the Employ Name : "); String name=dis.readLine(); System.out.println("Enter the Employ salary : "); float salary=Float.parseFloat(dis.readLine()); st.executeUpdate("insert values into Employee(id,'name',salary)"); } catch(Exception e) { e.printStackTrace(); } finally { con.close(); } }}

  Was this answer useful?  Yes

Supriya Ahire

  • Feb 2nd, 2007

Hello all,
Following are the simple steps of jdbc

1) Load the Driver using the statement Class.forName("Oracle.jdbc.driver.OracleDriver");

2) Establish connection to the oracle database.
Connection conn= DriverManager.getConnection("main prortocol:sub protocol:type4driver:name of oracle server:default port number(1521):service name", "username","password");

main protocol :Jdbc
Sub Protocol : Oracle
Type 4
Driver : thin

default port number is 1521
Service Name is Oracle9i
username is scott
password is Tiger

3) Design a query
String query="insert into table table name(?,?,?)";

4)Create a statment Object Using prepared statement.

PreparedStatement pstat= con.preparestatment(query);
here we need to pass the query,
we are passing dynamic query using prepared statement.

5)Execute Query using pstat

6) Close the connection

Ms.Supriya Ahire

  Was this answer useful?  Yes


  • Feb 9th, 2007

DriverManager.registerDriver(new Oracle:jdbc:OracleDriver());Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "scott", "tiger");

Step 1: Import JAVA Package:-
import java.sql.*;

Step 2: Register the driver with the following command:-

Step 3:- Create the connection with database:-
Connection cn = DriverManage.getConnection("Jdbc:Odbc:name of dsn");

Step 4:- Open the connection:-;

Step 5:- For Insertion of data:-
PreparedStatement ps = cn.prepareStatement("insert into <table name> values(?,?,?,?)");

Step 6:- Execute the command:-

Step 7:- Close the connection:-

NOTE:- Above step 7 is for only insertion of data.

"for retreival of data do same till step no 4 and then type the following command":-
ResultSet rs;

Rules of making DSN:-
Go to Control Panel -> Administrative Tools -> ODBC -> Add ->SQL Server -> Finish -> Name(any type) -> Next -> Next -> Folder name ->Next -> Finish -> Test -> Ok -> Finish.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.


Related Answered Questions


Related Open Questions