“不合适的驾驶员”运行时,但不在IDE中 [英] "No suitable driver" when running, but not in IDE
问题描述
我只是不明白....
public class Database {
Connection conn =空值;
语句stmt = null;
ResultSet rs = null;
public Database()throws SQLException {
String host =localhost:3306;
String schema =stickmanDatabase;
String user =richard;
String password =xxxxxxxx;
String url =jdbc:mysql://+ host +/+ schema +?user =+ user +& password =+ password;
try {
conn = DriverManager.getConnection(url);
} catch(SQLException e){
e.printStackTrace();
throw e;
}
}
}
这是我的堆栈跟踪获取:
java.sql.SQLException:找不到适合jdbc的驱动程序:mysql:// localhost:3306 / stickmanDatabase?user = java.sql.DriverManager.getConnection(未知来源)
java.sql.DriverManager.getConnection(未知来源)
在stickmanPyramidScheme.server.Database上的
& ; init>(Database.java:23)
在stickmanPyramidScheme.server.LoginVerification.verifyLogin(LoginVerification.java:10)
在stickmanPyramidScheme.server.StickmanServer.parseAndExecute(StickmanServer.java:55)
at stickmanPyramidScheme.server.StickmanServer.main(StickmanServer.java:32)
我的理解是问题是我需要在构建路径中使用文件mysql-connector-java-5.1.18-bin.jar,如果我删除它,代码在Eclipse中运行时不再有效。
任何帮助将不胜感激。谢谢。
...
根据Andrew的要求...我在Ubuntu Linux上使用Eclipse服务器。
我可以看到mysql-connector-java-5.1.18-bin.jar包含com.mysql.jdbc,其中包含Driver.class
该jar被添加到应用程序目录)/ WEB-INF / lib目录。并且仍然有相同的错误。
我想出了问题...
我的印象是Eclipse正在将所有文件放在一起,但是我需要在Manifest中添加类路径。将它放在清单中,但是添加一个-classpath选项,也不会将其添加到我的PATH中。
任何有类似问题的人都应该注意,你需要添加到Eclipse创建的jar中的MANIFEST.MF:
类路径:/path/file.jar
在文件末尾有空行
Can someone please please explain to me why the following code works when I run the app in the Eclipse IDE, but it generates an exception when compiled and run on a server? I just don't get it....
public class Database {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
public Database() throws SQLException {
String host = "localhost:3306";
String schema = "stickmanDatabase";
String user = "richard";
String password = "xxxxxxxx";
String url = "jdbc:mysql://" + host + "/" + schema + "?user=" + user + "&password=" + password;
try {
conn = DriverManager.getConnection(url);
} catch (SQLException e) {
e.printStackTrace();
throw e;
}
}
}
Here's the stacktrace I'm getting:
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/stickmanDatabase?user=richard&password=xxxxxxxx
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at stickmanPyramidScheme.server.Database.<init>(Database.java:23)
at stickmanPyramidScheme.server.LoginVerification.verifyLogin(LoginVerification.java:10)
at stickmanPyramidScheme.server.StickmanServer.parseAndExecute(StickmanServer.java:55)
at stickmanPyramidScheme.server.StickmanServer.main(StickmanServer.java:32)
My understanding is that the problem is that I need the file "mysql-connector-java-5.1.18-bin.jar in the build path, which I do. And if I remove it the code no longer works when running within Eclipse.
Any help would be greatly appreciated. Thanks.
...
Per Andrew's request... I am using Eclipse, on an Ubuntu Linux server. I can see that "mysql-connector-java-5.1.18-bin.jar" contains "com.mysql.jdbc" which contains the "Driver.class" The jar is added to the (application directory)/WEB-INF/lib directory. And still getting the same error.
I figured out the problem... I was under the impression that Eclipse was to take care of getting all the files together, but I needed to add the classpath in the Manifest. Putting it in the manifest worked, but adding a -classpath option nor adding it to my PATHs did not.
Anyone with a similar problem should note that you need to add this to the MANIFEST.MF in the jar that Eclipse creates:
Class-Path: /path/file.jar
With blank line at the end of the file
这篇关于“不合适的驾驶员”运行时,但不在IDE中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!