質問編集履歴
4
コードの変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -112,7 +112,7 @@
|
|
112
112
|
|
113
113
|
String user = "root";
|
114
114
|
|
115
|
-
String password = "
|
115
|
+
String password = "password";
|
116
116
|
|
117
117
|
String msg = "";
|
118
118
|
|
3
コードの変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -104,10 +104,20 @@
|
|
104
104
|
|
105
105
|
// TODO 自動生成されたメソッド・スタブ
|
106
106
|
|
107
|
+
|
108
|
+
|
107
|
-
|
109
|
+
Connection conn = null;
|
110
|
+
|
111
|
+
String url = "jdbc:mysql://localhost/helloworld?useSSL=false&requireSSL=false";
|
112
|
+
|
113
|
+
String user = "root";
|
114
|
+
|
115
|
+
String password = "gundamV2";
|
108
116
|
|
109
117
|
String msg = "";
|
110
118
|
|
119
|
+
|
120
|
+
|
111
121
|
try {
|
112
122
|
|
113
123
|
// ドライバロード
|
@@ -118,21 +128,19 @@
|
|
118
128
|
|
119
129
|
// MySQLに接続
|
120
130
|
|
121
|
-
|
131
|
+
conn = DriverManager.getConnection(url, user, password);
|
122
132
|
|
123
133
|
|
124
134
|
|
125
135
|
// ステートメント生成
|
126
136
|
|
127
|
-
Statement stmt = con.createStatement();
|
137
|
+
Statement stmt = conn.createStatement();
|
128
138
|
|
129
139
|
|
130
140
|
|
131
141
|
// SQLを実行
|
132
142
|
|
133
|
-
String sqlStr = "SELECT * FROM testhelloworld";
|
134
|
-
|
135
|
-
ResultSet rs = stmt.executeQuery(
|
143
|
+
ResultSet rs = stmt.executeQuery("SELECT * FROM test");
|
136
144
|
|
137
145
|
|
138
146
|
|
@@ -142,15 +150,13 @@
|
|
142
150
|
|
143
151
|
// レコードの値
|
144
152
|
|
145
|
-
int id = rs.getInt("
|
153
|
+
int Field = rs.getInt("helloworld");
|
146
|
-
|
147
|
-
|
154
|
+
|
148
|
-
|
149
|
-
|
155
|
+
|
150
156
|
|
151
157
|
//表示
|
152
158
|
|
153
|
-
System.out.println(id
|
159
|
+
System.out.println(Field);
|
154
160
|
|
155
161
|
}
|
156
162
|
|
@@ -162,8 +168,6 @@
|
|
162
168
|
|
163
169
|
stmt.close();
|
164
170
|
|
165
|
-
con.close();
|
166
|
-
|
167
171
|
}catch (ClassNotFoundException e){
|
168
172
|
|
169
173
|
msg = "ドライバのロードに失敗しました";
|
2
エラーとコードを修正しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,7 +12,35 @@
|
|
12
12
|
|
13
13
|
ドライバのロードに失敗しました
|
14
14
|
|
15
|
-
|
15
|
+
java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
|
16
|
+
|
17
|
+
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)
|
18
|
+
|
19
|
+
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
|
20
|
+
|
21
|
+
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
|
22
|
+
|
23
|
+
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
|
24
|
+
|
25
|
+
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
|
26
|
+
|
27
|
+
at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:905)
|
28
|
+
|
29
|
+
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:830)
|
30
|
+
|
31
|
+
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
|
32
|
+
|
33
|
+
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
|
34
|
+
|
35
|
+
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207)
|
36
|
+
|
37
|
+
at java.sql.DriverManager.getConnection(DriverManager.java:664)
|
38
|
+
|
39
|
+
at java.sql.DriverManager.getConnection(DriverManager.java:270)
|
40
|
+
|
41
|
+
at MyQuery.main(MyQuery.java:18)
|
42
|
+
|
43
|
+
Caused by: com.mysql.cj.exceptions.CJException: Access denied for user ''@'localhost' (using password: NO)
|
16
44
|
|
17
45
|
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
|
18
46
|
|
@@ -22,65 +50,33 @@
|
|
22
50
|
|
23
51
|
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
|
24
52
|
|
25
|
-
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
|
26
|
-
|
27
|
-
at com.mysql.jdbc.Util.getInstance(Util.java:408)
|
28
|
-
|
29
|
-
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
|
30
|
-
|
31
|
-
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898)
|
32
|
-
|
33
|
-
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887)
|
34
|
-
|
35
|
-
at com.mysql.j
|
53
|
+
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
|
36
|
-
|
37
|
-
|
54
|
+
|
38
|
-
|
39
|
-
at com.mysql.j
|
55
|
+
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105)
|
40
|
-
|
41
|
-
|
56
|
+
|
42
|
-
|
43
|
-
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
|
44
|
-
|
45
|
-
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
|
46
|
-
|
47
|
-
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
|
48
|
-
|
49
|
-
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
|
50
|
-
|
51
|
-
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
|
52
|
-
|
53
|
-
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
|
54
|
-
|
55
|
-
at com.mysql.j
|
57
|
+
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151)
|
58
|
+
|
56
|
-
|
59
|
+
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:129)
|
60
|
+
|
61
|
+
at com.mysql.cj.protocol.a.NativeProtocol.checkErrorMessage(NativeProtocol.java:809)
|
62
|
+
|
63
|
+
at com.mysql.cj.protocol.a.NativeProtocol.checkErrorMessage(NativeProtocol.java:734)
|
64
|
+
|
65
|
+
at com.mysql.cj.protocol.a.NativeProtocol.checkErrorMessage(NativeProtocol.java:702)
|
66
|
+
|
67
|
+
at com.mysql.cj.protocol.a.NativeProtocol.checkErrorMessage(NativeProtocol.java:132)
|
68
|
+
|
69
|
+
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.proceedHandshakeWithPluggableAuthentication(NativeAuthenticationProvider.java:540)
|
70
|
+
|
71
|
+
at com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:202)
|
72
|
+
|
57
|
-
at com.mysql.j
|
73
|
+
at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1442)
|
58
|
-
|
59
|
-
|
74
|
+
|
60
|
-
|
61
|
-
at java.sql.DriverManager.getConnection(DriverManager.java:270)
|
62
|
-
|
63
|
-
at MyQuery.main(MyQuery.java:18)
|
64
|
-
|
65
|
-
Caused by: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
|
66
|
-
|
67
|
-
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965)
|
68
|
-
|
69
|
-
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3978)
|
70
|
-
|
71
|
-
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3914)
|
72
|
-
|
73
|
-
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:871)
|
74
|
-
|
75
|
-
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1714)
|
76
|
-
|
77
|
-
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1224)
|
78
|
-
|
79
|
-
at com.mysql.j
|
75
|
+
at com.mysql.cj.NativeSession.connect(NativeSession.java:165)
|
80
|
-
|
76
|
+
|
81
|
-
at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:
|
77
|
+
at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:849)
|
82
|
-
|
78
|
+
|
83
|
-
...
|
79
|
+
... 7 more
|
84
80
|
|
85
81
|
|
86
82
|
|
@@ -116,7 +112,7 @@
|
|
116
112
|
|
117
113
|
// ドライバロード
|
118
114
|
|
119
|
-
Class.forName("com.mysql.
|
115
|
+
Class.forName("com.mysql.jdbc.Driver");
|
120
116
|
|
121
117
|
|
122
118
|
|
1
打ちなおしたものとエラーコードを追加しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,15 +8,87 @@
|
|
8
8
|
|
9
9
|
### 発生している問題・エラーメッセージ
|
10
10
|
|
11
|
-
|
11
|
+
```ここに言語を入力
|
12
12
|
|
13
13
|
ドライバのロードに失敗しました
|
14
14
|
|
15
|
-
|
15
|
+
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
|
16
|
+
|
17
|
+
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
|
18
|
+
|
19
|
+
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
|
20
|
+
|
21
|
+
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
|
22
|
+
|
23
|
+
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
|
24
|
+
|
25
|
+
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
|
26
|
+
|
27
|
+
at com.mysql.jdbc.Util.getInstance(Util.java:408)
|
28
|
+
|
29
|
+
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
|
30
|
+
|
31
|
+
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898)
|
32
|
+
|
33
|
+
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887)
|
34
|
+
|
35
|
+
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:861)
|
36
|
+
|
37
|
+
at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2105)
|
38
|
+
|
39
|
+
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2030)
|
40
|
+
|
41
|
+
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:778)
|
42
|
+
|
43
|
+
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
|
44
|
+
|
45
|
+
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
|
46
|
+
|
47
|
+
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
|
48
|
+
|
49
|
+
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
|
50
|
+
|
51
|
+
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
|
52
|
+
|
53
|
+
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
|
54
|
+
|
55
|
+
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:386)
|
56
|
+
|
57
|
+
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
|
58
|
+
|
59
|
+
at java.sql.DriverManager.getConnection(DriverManager.java:664)
|
60
|
+
|
61
|
+
at java.sql.DriverManager.getConnection(DriverManager.java:270)
|
62
|
+
|
63
|
+
at MyQuery.main(MyQuery.java:18)
|
64
|
+
|
65
|
+
Caused by: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
|
66
|
+
|
67
|
+
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965)
|
68
|
+
|
69
|
+
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3978)
|
70
|
+
|
71
|
+
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3914)
|
72
|
+
|
73
|
+
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:871)
|
74
|
+
|
75
|
+
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1714)
|
76
|
+
|
77
|
+
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1224)
|
78
|
+
|
79
|
+
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2199)
|
80
|
+
|
81
|
+
at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2046)
|
82
|
+
|
83
|
+
... 13 more
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
```
|
16
88
|
|
17
89
|
### 該当のソースコード
|
18
90
|
|
19
|
-
|
91
|
+
```該当のソースコード
|
20
92
|
|
21
93
|
import java.sql.Connection;
|
22
94
|
|
@@ -44,7 +116,7 @@
|
|
44
116
|
|
45
117
|
// ドライバロード
|
46
118
|
|
47
|
-
|
119
|
+
Class.forName("com.mysql.cj.jdbc.Driver");
|
48
120
|
|
49
121
|
|
50
122
|
|
@@ -102,19 +174,23 @@
|
|
102
174
|
|
103
175
|
System.out.println(msg);
|
104
176
|
|
177
|
+
e.printStackTrace();
|
178
|
+
|
105
179
|
}catch (Exception e){
|
106
180
|
|
107
181
|
msg = "ドライバのロードに失敗しました";
|
108
182
|
|
109
183
|
System.out.println(msg);
|
110
184
|
|
185
|
+
e.printStackTrace();
|
186
|
+
|
111
187
|
}
|
112
188
|
|
113
189
|
}
|
114
190
|
|
115
191
|
}
|
116
192
|
|
117
|
-
|
193
|
+
```
|
118
194
|
|
119
195
|
と出てしまうのでmysql-connector-java-5.1.47-bin.jarを入れるフォルダが間違っているのかなと思っています。
|
120
196
|
|