前提・実現したいこと
eclipse neon4.6を使用しています
別のPCのMysqlにアクセスしようとすると次のようなエラーが出てしまいます。
どのようにすれば解決できますか?
MysqlサーバのあるPCでは問題なく処理できています。
発生している問題・エラーメッセージ
Thu Jul 26 11:54:42 JST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'test'
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:425)
at com.mysql.jdbc.Util.getInstance(Util.java:408)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:944)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2480)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2438)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1381)
at test.TestSql.main(TestSql.java:25)
該当のソースコード
package test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class TestSql {
public static void main(String[] args) { String url = "jdbc:mysql://PCのID:3306/データベース名?autoReconnect=true&useSSL=false"; String user = "mysql"; String pass = "パスワード"; String sql = "SELECT * FROM 商品表"; String com = ""; try{ Class.forName("com.mysql.jdbc.NonRegisteringDriver"); Connection conn = (Connection)DriverManager.getConnection(url,user,pass); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql); rs.next(); com = rs.getString("短縮名"); System.out.println(com); rs.close(); stmt.close(); conn.close(); System.out.print("成功"); } catch (Exception e) { System.out.println("JDBCドライバのロードに失敗しました。"); } }
}
試したこと
データベース名の後の ?autoReconnect=true&useSSL=false" を削除しても同じエラーが出ました。
Class.forName("com.mysql.jdbc.NonRegisteringDriver"); を削除しても同じエラーが出ました。
eclipseのプラグインのDBViewerからは接続できましたが、
コードからだとエラーが出てしまうようです。
補足情報(FW/ツールのバージョンなど)
eclipse neon4.6
mysql5.7

回答4件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
また依頼した内容が修正された場合は、修正依頼を取り消すようにしましょう。
2018/08/08 05:43
2018/08/08 12:04
2018/08/10 07:25
2018/08/10 15:41
2018/08/20 07:14
2018/08/22 16:54
2018/08/24 07:22
2018/08/25 04:45
2018/08/29 06:19
2018/09/03 12:14 編集
2018/09/03 04:22
2018/09/03 12:15
2018/09/04 02:09
2018/09/04 13:08
2018/09/07 06:46
2018/09/07 13:34
2018/09/13 08:01
2018/09/27 12:45
2018/10/23 07:29