Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

843840Aug 2 2007 — edited Aug 6 2007
Hi
I have Oracle 10 G in a database server and trying to connect to the server through Java in the developers machine which also has oracle.
i have the driver (ojdbc14.jar) in java/lib and have also set the classpath. i am using eclipse . while trying to run the programme i get the following error

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at Finisher.MarkerFinishing.con(MarkerFinishing.java:16)
at Finisher.MarkerFinishing.main(MarkerFinishing.java:42)
Pall ----ClassNotFoundException: oracle.jdbc.driver.OracleDriver
markerFinishing---- Step AThu Aug 02 14:15:49 IST 2007
java.lang.NullPointerException
at Finisher.MarkerFinishing.A(MarkerFinishing.java:30)
at Finisher.MarkerFinishing.main(MarkerFinishing.java:46)

can anyone help me resolve it...
thanks

Comments

843840
try this :
Project --> Properties ---> Java Build Path ---> Libraries , in the list , add your jar to JRE node.
843840
hey thanx .. now i m being able to connect ... but getting a different error .. its nt being able to identify the SID...
i get the following error


java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
192.168.2.222:1521:DBSNP

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:261)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:420)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at Finisher.MarkerFinishing.con(MarkerFinishing.java:17)
at Finisher.MarkerFinishing.main(MarkerFinishing.java:41)


after this error... i have changed the port n is using the isqlplus port bt still its giving me the following erroe

java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:420)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at Finisher.MarkerFinishing.con(MarkerFinishing.java:17)
at Finisher.MarkerFinishing.main(MarkerFinishing.java:41)
800649
are you sure that DBSNP is the correct server instance id?

here an oracle typical connection code:
    Connection connection = null;
    try {
        // Load the JDBC driver
        String driverName = "oracle.jdbc.driver.OracleDriver";
        Class.forName(driverName);
    
        // Create a connection to the database
        String serverName = "127.0.0.1";
        String portNumber = "1521";
        String sid = "mydatabase";
        String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
        String username = "username";
        String password = "password";
        connection = DriverManager.getConnection(url, username, password);
    } catch (ClassNotFoundException e) {
        // Could not find the database driver
    } catch (SQLException e) {
        // Could not connect to the database
    }
843840
ya u r right my sid is snpdb and not dbsnp..
i ve corrected tht. and other things are same as u ve mentioned bt still i get the following error


java.lang.ClassCastException: oracle.jdbc.driver.T4CConnection
at Finisher.MarkerFinishing.con(MarkerFinishing.java:15)
at Finisher.MarkerFinishing.main(MarkerFinishing.java:32)
800649
post the MarkerFinishing.java line # 15 or all the code plz
843840
hi
i am posting the code as such..
i ve tried from eclipse as well as command line ..
and i get the following error

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver


import java.sql.DriverManager;
import java.sql.SQLException;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;

public class MarkerFinishing
{
String m_Trigger="dbSNP build 126";
Connection m_markerCon;
public void con() throws SQLException, java.lang.ClassNotFoundException{
Class.forName("oracle.jdbc.driver.OracleDriver"); // oracle driver
m_markerCon = (Connection)DriverManager.getConnection("jdbc:oracle:thin:@192.168.2.222:1521:SNPDB","g2p","g2p");

}
public void A() throws Exception{
//
Statement my_AStmt=(Statement) m_markerCon.createStatement();
System.out.println("Step A: Creating backup of replacedmarker");
// A.executeUpdate("DROP TABLE replacedmarker_temp");
my_AStmt.executeUpdate("create table replacedmarker_temp as(select * from replacedmarker)");
System.out.println("Step A: done");
my_AStmt.close();
}

public static void main(String[] args) {
try{
java.util.Date now=new java.util.Date();
MarkerFinishing mf=new MarkerFinishing();
mf.con();

now=new java.util.Date();
System.out.println("markerFinishing---- Step A" + now);
mf.A();
}catch(Exception e){
e.printStackTrace();
}
}
}
800649
You have problems in the imports part.
You should have imported java.sql.* instead of the mysql jdbc API related imports

Here the correct code:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;


public class MarkerFinishing {
	String m_Trigger = "dbSNP build 126";

	Connection m_markerCon;

	public void con() throws SQLException, java.lang.ClassNotFoundException {
		Class.forName("oracle.jdbc.driver.OracleDriver"); // oracle driver
		m_markerCon = (Connection) DriverManager.getConnection("jdbc:oracle:thin:@192.168.2.222:1521:SNPDB", "g2p", "g2p");

	}

	public void A() throws Exception {
		//
		Statement my_AStmt = (Statement) m_markerCon.createStatement();
		System.out.println("Step A: Creating backup of replacedmarker");
		// A.executeUpdate("DROP TABLE replacedmarker_temp");
		my_AStmt.executeUpdate("create table replacedmarker_temp as(select * from replacedmarker)");
		System.out.println("Step A: done");
		my_AStmt.close();
	}

	public static void main(String[] args) {
		try {
			java.util.Date now = new java.util.Date();
			MarkerFinishing mf = new MarkerFinishing();
			mf.con();

			now = new java.util.Date();
			System.out.println("markerFinishing---- Step A" + now);
			mf.A();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
Hope That Helps
1 - 7
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Sep 3 2007
Added on Aug 2 2007
7 comments
5,232 views