我有一个奇怪的问题。
使用NON Web应用程序,我会正常连接到我的数据库。当我在Web应用程序中尝试使用Servlet上的相同连接时,它不起作用,错误是:
java.sql.SQLException:没有为jdbc找到合适的驱动程序:mysql:// localhost / webtech
我把lib文件夹中的jar库放到web-inf文件夹中,我把jar放到apache-tomcat lib文件夹中,我把jar放到build path文件夹中,我尝试做“class for name”方法,但没有什么对我有用。
servet是一个简单的“hello world”servlet,用于测试连接。
答案 0 :(得分:0)
我解决了以下问题:
我将连接器的jar文件放入lib文件夹(web-inf文件夹中的文件夹)
代码:
String connectionString="jdbc:mysql://localhost:3306/webtech";
Connection con=null;
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
con=DriverManager.getConnection(connectionString,"root","root");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}