Java – Oracle jdbc driver not found
•
Java
I am a novice in Java and database connection. I am trying to establish a very simple connection with Oracle database When I run this Code:
import java.sql.*; import oracle.jdbc.pool.OracleDataSource; public class Hello { public String sayHtmlHello() { try { // Load the JDBC driver String driverName = "oracle.jdbc.driver.OracleDriver"; Class.forName(driverName); // Create a connection to the database String serverName = "sever2"; String portNumber = "1521"; String sid = "serv1"; String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber +":" + sid; String username = "user"; String password = "pass"; OracleDataSource ods = new OracleDataSource(); ods.setUser(username); ods.setPassword(password); ods.setURL(url); Connection conn = ods.getConnection(); System.out.println("Connection made?"); } catch (ClassNotFoundException e) { // Could not find the database driver System.out.println("Can't find database driver"); } catch (sqlException e) { // Could not connect to the database System.out.println("Can't connect to database"); }
I got the output and couldn't find the database driver I am using eclipse Helios, and I have ojdbc6 Jar was added to my build path (I checked it first), and I used JDK 1.6
Solution
Check Whether the jar is also on your running path In eclipse, go to run – > run configuration – > select your configuration – > classpath tab If you don't select "add jar" on the right, your jar needs to be in "user entry"
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码