如何修复:“在使用池时找不到JDBC:mysql:/localhost/dbName”错误?我试图创建到我的数据库的连接,当我使用主方法测试我的代码时,它是无缝工作的。然而,当试图通过Tomcat 7访问它时,它失败了,并出现了错误:No suitable driver found for jdbc:mysql://localhost/dbname.我用的是池。我在Web-INF/lib和.classpath中添加了MySQL连接器(5.1.15)、DBCP(1.4)和池(1.4.5)库。我正在使用EclipseIDE。我的数据库驱动程序代码是:import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;import org.apache.tomcat.dbcp.dbcp.ConnectionFactory;import org.apache.tomcat.dbcp.dbcp.DriverManagerConnectionFactory;import org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory;import org.apache.tomcat.dbcp.dbcp.PoolingDriver;import org.apache.tomcat.dbcp.pool.impl.GenericObjectPool;public class DatabaseConnector {
public static String DB_URI = "jdbc:mysql://localhost/dbname";
public static String DB_USER = "test";
public static String DB_PASS = "password";
// Singleton instance
protected static DatabaseConnector _instance;
protected String _uri;
protected String _username;
protected String _password;堆栈跟踪的开始:Apr 5, 2011 9:49:14 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [Login] in context with path [/Project]
threw exception
java.lang.RuntimeException: java.sql.SQLException:
No suitable driver found for jdbc:mysql://localhost/dbname是什么导致了这个错误?
3 回答
catspeake
TA贡献1111条经验 获得超0个赞
DriverManager.registerDriver(new com.mysql.jdbc.Driver ());
Class.forName("com.mysql.jdbc.Driver");
添加回答
举报
0/150
提交
取消