java.sql.SQLException:找不到适用于CONNECTION_URL的驱动程序

时间:2015-06-16 15:14:43

标签: java jdbc

我收到错误

  

java.sql.SQLException:找不到适用于CONNECTION_URL的驱动程序

这是一个连接提供程序java文件。

   package login;
    import java.sql.*;
    import java.sql.SQLException;

    public class ConnectionProvider {
    static Connection con = null;
    String database = "game";
    String CONNECTION_URL = "jdbc:mysql://localhost:3306/" + database;
    String USERNAME = "root";
    String PASSWORD = "";

    static {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("CONNECTION_URL", "USERNAME", "PASSWORD");
            Statement stmt = con.createStatement();

        } catch (SQLException sqle) {
            System.out.println("SQLException: Unable to open connection to db: "+sqle.getMessage());
            try {
                throw sqle;
            } catch (SQLException e) {
                e.printStackTrace();
            }
        } catch(Exception e) {
            System.out.println("Exception: Unable to open connection to db: "+e.getMessage());
            try {
                throw e;
            } catch (ClassNotFoundException e1) {
                e1.printStackTrace();
            }
        }
    }
}

我正在使用navicat,mysql和tomcat sv。我很确定他们在跑步。这是IntelliJ的日志。

SQLException: Unable to open connection to db: No suitable driver found for CONNECTION_URL
java.sql.SQLException: No suitable driver found for CONNECTION_URL
    at java.sql.DriverManager.getConnection(DriverManager.java:689)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at login.ConnectionProvider.<clinit>(ConnectionProvider.java:18)
    at login.loginDAO.validate(loginDAO.java:21)
    at login.loginDAO.doPost(loginDAO.java:56)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2463)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2452)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

谢谢你的帮助

1 个答案:

答案 0 :(得分:0)

你引用了两个变量:

con = DriverManager.getConnection("CONNECTION_URL", "USERNAME", "PASSWORD");

应该是

con = DriverManager.getConnection(CONNECTION_URL, USERNAME, PASSWORD);

因此,java正在尝试查找名为CONNECTION_URL

的数据库驱动程序