我尝试查看与此问题相关的每个答案,但仍然给我同样的错误。我尝试将jar文件包含到我的项目中,但仍然无法正常工作。请帮我。这是我的servlet文件。
package com.test.testdb;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class TestDbServlet
*/
@WebServlet("/TestDbServlet")
public class TestDbServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request,
HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
String user = "test";
String pass = "test";
String jdbcUrl = "jdbc:mysql://localhost:3306/test?
useSSL=false";
String driver = "com.mysql.jdbc.Driver";
try {
PrintWriter out = response.getWriter();
out.println("Connecting to database: " + jdbcUrl);
Class.forName(driver);
Connection myConn = DriverManager.getConnection(jdbcUrl, user, pass);
out.println("yay");
myConn.close();
}
catch (Exception exc) {
exc.printStackTrace();
throw new ServletException(exc);
}
}
}
我已经将mysql-connector-java-5.1.47-bin.jar添加到我的WEB-INF> lib文件夹中。我对此并不陌生,所以我仍在尝试解决问题。请帮我。这是我运行文件时得到的。
连接到数据库:jdbc:mysql:localhost:3306 / test java.sql.SQLException:找不到适用于> jdbc:mysql:localhost:3306 / test的合适驱动程序 在java.sql.DriverManager.getConnection(未知来源) 在java.sql.DriverManager.getConnection(未知来源) 在com.hibernate_tutorial.jdbc.Driver.main(Driver.java:16)