Error while making connection to Oracle database in JDBC
I have written a code to c开发者_如何学JAVAheck whether connection is successful or not. But its giving error. I have a oracle 10g express edition instsalled on my computer.
try{
String url="jdbc:oracle:thin:@//localhost:1521:XE";
String driver= "oracle.jdbc.driver.OracleDriver";
Class.forName(driver);
System.out.println(" Driver loaded ");
Connection con = DriverManager.getConnection(url,"system:,"manager");
System.out.println("Connection Successful");
} //catch block
The error given is:
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
Thanks for help.
you need to add oracle jdbc driver (jar) to your class path.
Looks like the JAR file containing the oracle.jdbc.driver.OracleDriver
class is simply not on your classpath. Find it and fix that problem by adding the location (e.g., via the -cp
option to java
; the details of how to fix it will vary by the kind of application you're building).
Add ojdbc.jar in classpath.
Check this for How to Add JARs to Project Build Paths in Eclipse
You have to put the oracle_jdbc.jar
file in the same folder of your code, or anywhere else and add that folder to your classpath.
精彩评论