我正在尝试在 Eclipse 中连接到 Oracle 数据库。我在同一项目的 lib 文件夹中有 ojdbc14.jar,并将其添加到项目的构建路径中,因此它也驻留在引用的库目录中,但我仍然在控制台中得到“无法找到数据库驱动程序”的输出
我自己和另一位学生员工在过去的一天半里一直在努力解决这个问题,而且我们部门中没有其他人有 Java 和 JSP 经验,所以我认为 StackOverflow 将是我们最好的选择 =)
try {
// Load the JDBC driver
String driverName = "oracle.jdbc.driver.OracleDriver";
System.out.println("Attempting to load the driver...");
Class.forName(driverName);
System.out.print("Loaded the driver");
// Create a connection to the database
String serverName = " ;) ";
String portNumber = " ;) ";
String sid = " ;) ";
String url = "jdbc:oracle:thin:@" + serverName + ":"
+ portNumber + ":" + sid;
String username = "kenne13";
String password = "**********";
connection = DriverManager.getConnection(url, username, password);
if (connection != null) {
return true;
}
} catch (ClassNotFoundException e) {
// Could not find the database driver
System.out.println("Could not find the database driver");
connected = false;
} catch (SQLException e) {
// Could not connect to the database
System.out.println("Could not connect to the database");
connected = false;
}
这是控制台中的输出:
Aug 18, 2011 10:07:50 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 382 ms
Attempting to load the driver...
Could not find the database driver
Here是代码、错误和我的项目目录的屏幕截图。
最佳答案
我现在非常确定驱动程序的类名称是 oracle.jdbc.OracleDriver
而不是 oracle.jdbc.driver.OracleDriver
。
关于java - Eclipse JAVA程序中找不到Oracle数据库驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7109144/