how to connect java with oracle

31 views
Skip to first unread message

nirmala nimmy

unread,
May 2, 2010, 5:24:44 AM5/2/10
to vogella
i wrote following code to connect java with oracle
import java.sql.*;


/**
* @author Nims
*
*/
public class OracleDataFactory {

public static void main(String args[]) {

String userName = "query";
String passWord = "query";

String urlString = "jdbc:oracle:oci8:@";
String DB_CONN_STRING = "oracle.jdbc.driver.OracleDriver";
//String urlString = "jdbc:oracle:thin:queryOptimisation";

Connection con = null;

try
{

Class.forName(DB_CONN_STRING);
//DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

con= DriverManager.getConnection(urlString, userName,passWord);

Statement stmt = con.createStatement();
ResultSet rset = stmt.executeQuery("select * from
clustercosttable ");
while (rset.next())
System.out.println (rset.getString(1));
stmt.close();
}




catch (ClassNotFoundException e) {
System.out.println("ClassNotFoundException"+e);
e.printStackTrace();
} catch (SQLException e) {
System.out.println("SQLException"+e);
e.printStackTrace();
}

}
}

D:\>javac OracleDataFactory.java

D:\>java OracleDataFactory
ClassNotFoundExceptionjava.lang.ClassNotFoundException:
oracle.jdbc.driver.Oracl
eDriver
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at OracleDataFactory.main(OracleDataFactory.java:24)
while compile and run i got this error can any one help me

--
You received this message because you are subscribed to the Google Groups "vogella" group.
To post to this group, send email to vog...@googlegroups.com.
To unsubscribe from this group, send email to vogella+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/vogella?hl=en.

tjeerd....@gmail.com

unread,
May 3, 2010, 9:05:39 AM5/3/10
to vogella
It seams that at runtime the driver class
oracle.jdbc.driver.OracleDriver is not available. Check your runtime
classpath.

George

unread,
May 2, 2010, 8:19:06 AM5/2/10
to vog...@googlegroups.com
Stating the obvious, do have the Oracle driver installed correctly?
Reply all
Reply to author
Forward
0 new messages