0
私はMySQLサーバへの接続に問題があるのUbuntu 16.04サーバー上にインストールされているが、私はこれらのエラーを得た:私はNavicateのようなMySQLのクライアントアプリケーションを使用してサーバーに接続することができますは、MySQLサーバに接続できません - Javaの
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1117)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:355)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2461)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2498)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2283)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:822)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:404)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at schoolcontroller.tools.DataBase.mysql.DataAccess.connect(DataAccess.java:45)
at schoolcontroller.tools.DataBase.mysql.DataAccess.main(DataAccess.java:40)
とエラーのないMySQLワークベンチ。ここで
は私のコード
public DataAccess() throws ClassNotFoundException {
Class.forName("com.mysql.jdbc.Driver");
}
public static void main(String[] args) throws SQLException, ClassNotFoundException {
System.out.println("Connecting");
new DataAccess().connect();
}
public void connect() throws SQLException {
String connection = "jdbc:mysql://%s:%s/%s?useUnicode=true&characterEncoding=UTF-8";
conn = DriverManager.getConnection(String.format(connection, "IPAddress", "3306", "DBname"), "user", "pass");
System.out.println("Connected");
st = conn.createStatement();
}
ポートとユーザ名、データベース名、およびIPは正しいです。