aspose file tools*
The moose likes JDBC 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
Bookmark "Connection to Oracle Database " Watch "Connection to Oracle Database " New topic
Author

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
Greenhorn

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 (http://download-west.oracle.com/docs/cd/B10501_01/java.920/a96654/toc.htm). I hope you have already downloaded jdbc driver for oracle. You can find it on oracle site

/*
* TestOracle.java
*
* 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 {
Class.forName("oracle.jdbc.OracleDriver");
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.next()) {
System.out.println(
rset.getInt(1) + "," +
rset.getString(2) + "," +
rset.getString(3) + "," +
rset.getInt(4) + "," +
rset.getDate(5) + "," +
rset.getInt(6) + "," +
rset.getInt(7) + "," +
rset.getInt(8));
}
conn.close();
} catch(ClassNotFoundException clExcp) {
System.out.println("Driver Error" + clExcp.getMessage());
} catch(SQLException sqlExcp) {
System.out.println("Connection Error" +
sqlExcp.getMessage());
}

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

Joined: Nov 26, 2004
Posts: 18
You can download Oracle JDBC driver jar file from this link
http://www.oracle.com/technology/software/htdocs/distlic.html?/technology/software/tech/java/sqlj_jdbc/htdocs/jdbc9201.html
satish kumar
Greenhorn

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

http://java.sun.com/j2se/1.3/docs/tooldocs/win32/classpath.html
 
jQuery in Action, 2nd edition
 
subject: Connection to Oracle Database