Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC ClassNotFoundException help please

 
sanket jani
Ranch Hand
Posts: 47
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello everyone ,

i am using a windows-8 64-bit operating system.

whenever i try to run this code it give the error about classnotfoundexception ..

how i recover from that.

i think there is a some driver problem..

following is the code which i try..

import java.sql.*;
class OracleCon{
public static void main(String args[]){
try{
//step1 load the driver class
Class.forName("oracle.jdbc.driver.OracleDriver");


//step2 create the connection object
Connection con=DriverManager.getConnection("jdbcracle:thin:@localhost:1521:xe","system","oracle");

//step3 create the statement object
Statement stmt=con.createStatement();

//step4 execute query
ResultSet rs=stmt.executeQuery("select * from emp");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));

//step5 close the connection object
con.close();

}catch(Exception e){ System.out.println(e);}

}
}
 
K. Tsang
Bartender
Posts: 3583
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you set your classpath pointing to the Oracle JDBC jar file?
 
sanket jani
Ranch Hand
Posts: 47
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No .
Can you please guide me how i set this .jar file in my laptop.
i am using windows-8 , 64-bit O.S
 
K. Tsang
Bartender
Posts: 3583
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Say your oracle jdbc jar is in c:\temp then

java -cp c:/temp/ojdbc6.jar OracleCon

The path to the jar file can be relative to where you are running your code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic