LoginSignup
0
1

More than 3 years have passed since last update.

DBViewerをプラグインしているEclipseからMySQLに接続

Posted at

eclipseでWebアプリケーション作成を目指して
本をトレースしているなかMySQLの接続をしようとして
接続ができなかったの健忘録です。

TestMySQL.java

Class.forName("com.mysql.jdbc.Driver");
String url ="jdbc:mysql://localhost:3306/dbName";
String user = "username";
String password = "password";
Connection conn = DriverManager.getConnection(url.user,password);

前後を割愛していますが、
これで、まずこういうエラーが出ました。

error.message

Loading class 'com.mysql.jdbc.Driver' This is deprecated.
The new driver class is 'com.mysql.cj.jdbc.Driver'

なのでドライバーの名前をcom.mysql.cj.jdbc.Driverに変更しました

TestMySQL2.java

Class.forName("com.mysql.cj.jdbc.Driver");
String url ="jdbc:mysql://localhost:3306/dbName";
String user = "username";
String password = "password";
Connection conn = DriverManager.getConnection(url.user,password);

ところがこれでもエラーが出ました。
タイムゾーンがうんたら・・・という内容でした。
(ログを取るの忘れました…)

ググってみるとこちらのサイトにある
タイムゾーンの設定の記述でうまく接続できました。

参考:https://kurukuruz.hatenablog.jp/entry/2018/04/28/200000 

TestMySQL3.java

Class.forName("com.mysql.cj.jdbc.Driver");
String url ="jdbc:mysql://localhost:3306/dbName?characterEncodeing=UTF-8&serverTimezone=JST";String user="pcklog";String password="p!cklog";
Connection conn = riverManager.getConnection(url.user,password);

補足:
MySQL Server5.7のほうにmy.iniを作成して
タイムゾーンの設定をするのは上手く動きませんでした。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1