我在MyEclipse里写了下面这个连接:
ConnectionManager() { try {
Class.forName("com.mysql.jdbc.Driver");
} catch (java.lang.ClassNotFoundException e) {
System.err.println(e.getMessage());
}
try {
if (pvt_dbConn == null) {
pvt_dbConn = DriverManager
.getConnection("jdbc:mysql://localhost/test?user=test&password=test");
}
} catch (SQLException ex) {
// TODO Log will be needed, right now only sends command line debug.
System.out.println("SQLException: " + ex.getMessage());
} }mysql-connector-java-5.0.4-bin.jar这个jar包加到项目的lib文件夹中。
在MyEclipse里面直接运行应用程序时很正常。
但是把程序导出成可执行的jar包运行时,就会报错:
com.mysql.jdbc.Driver
SQLException: No suitable driver found for jdbc:mysql://localhost/test?user=test&password=test打开程序的jar包,mysql-connector-java-5.0.4-bin.jar已经包含在lib文件夹中,
.classpath文件也已经加了:
<classpathentry kind="lib" path="lib/mysql-connector-java-5.0.4-bin.jar"/>
请问高手这是什么原因?
ConnectionManager() { try {
Class.forName("com.mysql.jdbc.Driver");
} catch (java.lang.ClassNotFoundException e) {
System.err.println(e.getMessage());
}
try {
if (pvt_dbConn == null) {
pvt_dbConn = DriverManager
.getConnection("jdbc:mysql://localhost/test?user=test&password=test");
}
} catch (SQLException ex) {
// TODO Log will be needed, right now only sends command line debug.
System.out.println("SQLException: " + ex.getMessage());
} }mysql-connector-java-5.0.4-bin.jar这个jar包加到项目的lib文件夹中。
在MyEclipse里面直接运行应用程序时很正常。
但是把程序导出成可执行的jar包运行时,就会报错:
com.mysql.jdbc.Driver
SQLException: No suitable driver found for jdbc:mysql://localhost/test?user=test&password=test打开程序的jar包,mysql-connector-java-5.0.4-bin.jar已经包含在lib文件夹中,
.classpath文件也已经加了:
<classpathentry kind="lib" path="lib/mysql-connector-java-5.0.4-bin.jar"/>
请问高手这是什么原因?
不过我想问,如果每次打jar包都要把它拷贝到C:\Program Files\Java\jre1.5.0_11\lib\ext目录下,这样不是很麻烦吗?有没有自动把它拷贝过去的办法?