It's not a secret anymore!
The moose likes JDBC and Relational Databases and the fly likes Connection to Oracle Database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Connection to Oracle Database " Watch "Connection to Oracle Database " New topic

Connection to Oracle Database

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
I have oracle installed on my machine .

Please any body can mail me a program that is using oracle as a database & performing any SQL query .

Please mention also that which file I have to set in class path if any ?
Please provide command for setting that file into class path .

thanks .
god bless you .
satish kumar

Joined: Nov 26, 2004
Posts: 18
Here is the code I wrote to test my oracle connection. This link gives you more information on how to connect to Oracle ( I hope you have already downloaded jdbc driver for oracle. You can find it on oracle site

* Created on December 21, 2004, 7:45 PM

package acrostics;

* @author Satish
import java.sql.*;
import java.math.*;
public class TestOracle {

/** Creates a new instance of TestOracle */
public TestOracle() {
try {
Connection conn = DriverManager.getConnection(
"jdbc racle:thin:@mydb:1521:satish", "scott", "tiger");
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("SELECT * FROM emp");
while ( {
rset.getInt(1) + "," +
rset.getString(2) + "," +
rset.getString(3) + "," +
rset.getInt(4) + "," +
rset.getDate(5) + "," +
rset.getInt(6) + "," +
rset.getInt(7) + "," +
} catch(ClassNotFoundException clExcp) {
System.out.println("Driver Error" + clExcp.getMessage());
} catch(SQLException sqlExcp) {
System.out.println("Connection Error" +

public static void main(String[] args) {
TestOracle ora1 = new TestOracle();
satish kumar

Joined: Nov 26, 2004
Posts: 18
You can download Oracle JDBC driver jar file from this link
satish kumar

Joined: Nov 26, 2004
Posts: 18
I see from your earlier post that you already have driver. You may move it to the folder that is already set in your classpath variable. For instance, you can move it to the directory where you have your other classes that ran fine. Alternatively, you can add the location of your driver to classpath. The following link will help you in setting the classpath. Sometimes IDE (if you are using one) has option to add a folder/jar file to your project. NetBeans has that kind of option and that's what I used
I agree. Here's the link:
subject: Connection to Oracle Database
It's not a secret anymore!