jdbc:无法创建与数据库服务器的连接

时间:2019-08-05 13:38:17

标签: mysql jdbc

我正在尝试使用Java与Mysql数据库连接。我进行了全新的Windows 7安装,还安装了JDK(12),Netbeans(11.1)和Mysql(8.0.17)的最新版本。 jdbc库的版本为8.0.17。

代码:

    try {    
        Connection con = DriverManager.getConnection("jdbc:mysql://"
            + "127.0.0.1:3306/raspiOne?"
            + "useTimezone=true&serverTimezone=UTC"
            + "user=root&"
            + "password=labor01"
            + "&useSSL=false");

    } 
    catch (SQLException ex) {

        System.out.println("SQLException: " + ex.getMessage());
        System.out.println("SQLState: " + ex.getSQLState());
        System.out.println("VendorError: " + ex.getErrorCode());

        Logger.getLogger(Databasetest.class.getName()).log(Level.SEVERE, null, ex);
    }

例外:

    SQLException: Could not create connection to database server.
    SQLState: 08001
    VendorError: 0
    Aug. 05, 2019 3:24:16 NACHM. raspberryone.TestingGrounds.Databasetest connect
    SEVERE: null
    com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
        at com.mysql.jdbc.Util.getInstance(Util.java:387)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:917)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:896)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:885)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
        at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2330)
        at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2083)
        at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:806)
        at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
        at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:410)
        at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:328)
        at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)
        at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:251)
        at raspberryone.TestingGrounds.Databasetest.connect(Databasetest.java:21)
        at raspberryone.RaspberryOne.main(RaspberryOne.java:92)
    Caused by: java.lang.NullPointerException
        at com.mysql.jdbc.ConnectionImpl.getServerCharset(ConnectionImpl.java:2997)
        at com.mysql.jdbc.MysqlIO.sendConnectionAttributes(MysqlIO.java:1936)
        at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1865)
        at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1228)
        at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2253)
        at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2284)
        ... 15 more

1 个答案:

答案 0 :(得分:1)

您忘记了时区和之后的时间

// src/Model/Table/FiltersTable.php
public function findFilters(Query $query, array $options)
{
     // $query->find() ...
     // ...
     return $query;
}