不能在Eclipse JAVA程序
找到Oracle数据库驱动程序,我试图连接到Oracle数据库中的日食。我在同一个项目的lib文件夹中添加了ojdbc14.jar,并将其添加到我的项目的构建路径中,因此它也驻留在Referenced Libraries目录中,但我仍然得到输出到控制台“Could not find数据库驱动程序“不能在Eclipse JAVA程序
我和另一位学生员工一直试图在过去的一天半里得出这个结论,我们部门中没有其他人在Java和JSP方面有经验,所以我认为*将是我们最好的赌注=)
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
。
你打败了我! – dontocsata
我改变了,但我仍然得到相同的错误?你看看我的目录结构吗? Idk确定,但是可能存在的问题 –
您是否已将该库添加到J2EE模块相关性中?这[博客文章](http://tuldoksystem.wordpress.com/2007/11/06/adding-libraries-to-a-dynamic-web-application-in-eclipse/)解释了如何做到这一点。有几种方法可以在eclipse中添加库,而不是所有的方法都会在部署时将其添加到Web应用程序中。 – Augusto
我相信Oracle驱动程序类是:oracle.jdbc.OracleDriver
我改变了它,但我仍然得到相同的错误?你看看我的目录结构吗? Idk肯定,但是这个箴言可能在那里 –
转到您的Web应用程序的deploy文件夹(C:\ Program Files \ Apache Software Foundation \ Tomcat 6.0 \ webapps),并确保ojdbc14.jar在那里。
你可以尝试改变与'oracle.jdbc.OracleDriver'驱动类的名字吗? – Augusto
试过了,但仍然捕获ClassNotFoundException并显示相同的错误??? –