質問編集履歴
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -298,7 +298,7 @@
|
|
298
298
|
|
299
299
|
###追記
|
300
300
|
|
301
|
-
javaファイルを
|
301
|
+
javaファイルを変更しましたら下記のエラーが出てしまいました
|
302
302
|
|
303
303
|
|
304
304
|
|
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -92,458 +92,294 @@
|
|
92
92
|
|
93
93
|
```
|
94
94
|
|
95
|
+
|
96
|
+
|
95
|
-
###
|
97
|
+
###servlet
|
96
98
|
|
97
99
|
```
|
98
100
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
<td height=70><%=rs.getString("user_id") %></td>
|
290
|
-
|
291
|
-
<td height=70><%=rs.getString("password") %></td>
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
<%
|
101
|
+
package servlet;
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
import java.io.IOException;
|
106
|
+
|
107
|
+
import java.sql.Connection;
|
108
|
+
|
109
|
+
import java.sql.PreparedStatement;
|
110
|
+
|
111
|
+
import java.sql.ResultSet;
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
import javax.naming.InitialContext;
|
116
|
+
|
117
|
+
import javax.servlet.ServletException;
|
118
|
+
|
119
|
+
import javax.servlet.annotation.WebServlet;
|
120
|
+
|
121
|
+
import javax.servlet.http.HttpServlet;
|
122
|
+
|
123
|
+
import javax.servlet.http.HttpServletRequest;
|
124
|
+
|
125
|
+
import javax.servlet.http.HttpServletResponse;
|
126
|
+
|
127
|
+
import javax.servlet.http.HttpSession;
|
128
|
+
|
129
|
+
import javax.sql.DataSource;
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
@WebServlet("/user_edit")
|
134
|
+
|
135
|
+
public class user_edit extends HttpServlet {
|
136
|
+
|
137
|
+
private static final long serialVersionUID = 1L;
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
protected void doPost(HttpServletRequest request,
|
142
|
+
|
143
|
+
HttpServletResponse response) throws ServletException, IOException {
|
144
|
+
|
145
|
+
request.setCharacterEncoding("UTF-8");
|
146
|
+
|
147
|
+
String userId = request.getParameter("user_id");
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
Connection con = null;
|
152
|
+
|
153
|
+
PreparedStatement ps = null;
|
154
|
+
|
155
|
+
String sql = null;
|
156
|
+
|
157
|
+
ResultSet rs = null;
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
// セッションを取得する
|
162
|
+
|
163
|
+
HttpSession session = request.getSession();
|
164
|
+
|
165
|
+
// 変数の初期化
|
166
|
+
|
167
|
+
boolean userResult = false;
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
if (session.getAttribute("userResult") != null) {
|
172
|
+
|
173
|
+
userResult = (boolean) session.getAttribute("userResult");
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
if (userResult) {
|
180
|
+
|
181
|
+
try {
|
182
|
+
|
183
|
+
// データベースの接続を確立
|
184
|
+
|
185
|
+
InitialContext initContext = new InitialContext();
|
186
|
+
|
187
|
+
DataSource ds = (DataSource) initContext
|
188
|
+
|
189
|
+
.lookup("java:comp/env/jdbc/Library");
|
190
|
+
|
191
|
+
con = ds.getConnection();
|
192
|
+
|
193
|
+
//
|
194
|
+
|
195
|
+
sql = "UPDATE user SET (first_name,last_name,first_name_kana,last_name_kana,user_id,password)=(?,?,?,?,?,?) WHERE user_id=?";
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
// UPDATE命令の準備
|
200
|
+
|
201
|
+
ps = con.prepareStatement(sql);
|
202
|
+
|
203
|
+
// UPDATE命令にポストデータの内容をセット
|
204
|
+
|
205
|
+
ps.setString(1, request.getParameter("first_name"));
|
206
|
+
|
207
|
+
ps.setString(2, request.getParameter("last_name"));
|
208
|
+
|
209
|
+
ps.setString(3, request.getParameter("first_name_kana"));
|
210
|
+
|
211
|
+
ps.setString(4, request.getParameter("last_name_kana"));
|
212
|
+
|
213
|
+
ps.setString(5, request.getParameter("user_id"));
|
214
|
+
|
215
|
+
ps.setString(6, request.getParameter("password"));
|
216
|
+
|
217
|
+
ps.setString(7, userId);
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
// UPDATE命令を実行
|
222
|
+
|
223
|
+
ps.executeUpdate();
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
// UPDATE命令後の画面遷移
|
228
|
+
|
229
|
+
this.getServletContext().getRequestDispatcher("/user_edit.jsp")
|
230
|
+
|
231
|
+
.forward(request, response);
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
} catch (Exception e) {
|
236
|
+
|
237
|
+
throw new ServletException(e);
|
238
|
+
|
239
|
+
} finally {
|
240
|
+
|
241
|
+
try {
|
242
|
+
|
243
|
+
if (rs != null) {
|
244
|
+
|
245
|
+
rs.close();
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
if (ps != null) {
|
250
|
+
|
251
|
+
ps.close();
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
if (con != null) {
|
256
|
+
|
257
|
+
con.close();
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
} catch (Exception e) {
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
} else {
|
270
|
+
|
271
|
+
// エラーメッセージをリクエスト格納
|
272
|
+
|
273
|
+
request.setAttribute("errorMessage", "ログインが行われていません。");
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
// ログイン画面遷移
|
278
|
+
|
279
|
+
this.getServletContext().getRequestDispatcher("/Login.jsp")
|
280
|
+
|
281
|
+
.forward(request, response);
|
282
|
+
|
283
|
+
}
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
}
|
288
|
+
|
289
|
+
|
296
290
|
|
297
291
|
}
|
298
292
|
|
299
|
-
|
293
|
+
|
300
|
-
|
301
|
-
throw new ServletException(e);
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
}finally{
|
306
|
-
|
307
|
-
try{
|
308
|
-
|
309
|
-
if(rs != null){rs.close();}
|
310
|
-
|
311
|
-
if(rs != null){ps.close();}
|
312
|
-
|
313
|
-
if(rs != null){con.close();}
|
314
|
-
|
315
|
-
}catch(Exception e){}
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
}
|
320
|
-
|
321
|
-
%>
|
322
|
-
|
323
|
-
</table>
|
324
|
-
|
325
|
-
<form action="kanri_mypage.jsp">
|
326
|
-
|
327
|
-
<input style="color:white;
|
328
|
-
|
329
|
-
background-color:D57200;" type="submit" value="TOPページ">
|
330
|
-
|
331
|
-
</form>
|
332
|
-
|
333
|
-
<form action="user_kanri.jsp">
|
334
|
-
|
335
|
-
<input style="color:white;
|
336
|
-
|
337
|
-
background-color:D57200;" type="submit" value="戻る">
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
</form>
|
344
|
-
|
345
|
-
</body>
|
346
|
-
|
347
|
-
</html>
|
348
294
|
|
349
295
|
```
|
350
296
|
|
351
297
|
|
352
298
|
|
353
|
-
###
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
DataSource ds = (DataSource) initContext
|
442
|
-
|
443
|
-
.lookup("java:comp/env/jdbc/Library");
|
444
|
-
|
445
|
-
con = ds.getConnection();
|
446
|
-
|
447
|
-
// SQL
|
448
|
-
|
449
|
-
sql = "UPDATE user SET (first_name,last_name,first_name_kana,last_name_kana,"
|
450
|
-
|
451
|
-
+ "user_id,password)=(?,?,?,?,?,?) WHERE user_id=?";
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
// UPDATE命令の準備
|
456
|
-
|
457
|
-
ps = con.prepareStatement(sql);
|
458
|
-
|
459
|
-
// UPDATE命令にポストデータの内容をセット
|
460
|
-
|
461
|
-
ps.setString(1, request.getParameter("first_name"));
|
462
|
-
|
463
|
-
ps.setString(2, request.getParameter("last_name"));
|
464
|
-
|
465
|
-
ps.setString(3, request.getParameter("first_name_kana"));
|
466
|
-
|
467
|
-
ps.setString(4, request.getParameter("last_name_kana"));
|
468
|
-
|
469
|
-
ps.setString(5, request.getParameter("user_id"));
|
470
|
-
|
471
|
-
ps.setString(6, request.getParameter("password"));
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
// UPDATE命令を実行
|
476
|
-
|
477
|
-
ps.executeUpdate();
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
// UPDATE命令後の画面遷移
|
482
|
-
|
483
|
-
this.getServletContext().getRequestDispatcher("/user_edit.jsp")
|
484
|
-
|
485
|
-
.forward(request, response);
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
} catch (Exception e) {
|
490
|
-
|
491
|
-
throw new ServletException(e);
|
492
|
-
|
493
|
-
} finally {
|
494
|
-
|
495
|
-
try {
|
496
|
-
|
497
|
-
if (rs != null) {
|
498
|
-
|
499
|
-
rs.close();
|
500
|
-
|
501
|
-
}
|
502
|
-
|
503
|
-
if (ps != null) {
|
504
|
-
|
505
|
-
ps.close();
|
506
|
-
|
507
|
-
}
|
508
|
-
|
509
|
-
if (con != null) {
|
510
|
-
|
511
|
-
con.close();
|
512
|
-
|
513
|
-
}
|
514
|
-
|
515
|
-
} catch (Exception e) {
|
516
|
-
|
517
|
-
}
|
518
|
-
|
519
|
-
}
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
} else {
|
524
|
-
|
525
|
-
// エラーメッセージをリクエスト格納
|
526
|
-
|
527
|
-
request.setAttribute("errorMessage", "ログインが行われていません。");
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
// ログイン画面遷移
|
532
|
-
|
533
|
-
this.getServletContext().getRequestDispatcher("/Login.jsp")
|
534
|
-
|
535
|
-
.forward(request, response);
|
536
|
-
|
537
|
-
}
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
}
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
}
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
```
|
299
|
+
###追記
|
300
|
+
|
301
|
+
javaファイルを下記のしたところ下記のエラーが出てしまいました
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
↓ ↓ ↓ ↓ ↓
|
306
|
+
|
307
|
+
HTTPステータス 500 - com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(first_name,last_name,first_name_kana,last_name_kana,user_id,password)=('aa','aa' at line 1
|
308
|
+
|
309
|
+
type 例外レポート
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
メッセージ com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(first_name,last_name,first_name_kana,last_name_kana,user_id,password)=('aa','aa' at line 1
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
説明 The server encountered an internal error that prevented it from fulfilling this request.
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
例外
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
javax.servlet.ServletException: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(first_name,last_name,first_name_kana,last_name_kana,user_id,password)=('aa','aa' at line 1
|
326
|
+
|
327
|
+
servlet.user_edit.doPost(user_edit.java:69)
|
328
|
+
|
329
|
+
javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
|
330
|
+
|
331
|
+
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
|
332
|
+
|
333
|
+
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
|
334
|
+
|
335
|
+
原因
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(first_name,last_name,first_name_kana,last_name_kana,user_id,password)=('aa','aa' at line 1
|
340
|
+
|
341
|
+
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
|
342
|
+
|
343
|
+
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
|
344
|
+
|
345
|
+
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
|
346
|
+
|
347
|
+
java.lang.reflect.Constructor.newInstance(Constructor.java:422)
|
348
|
+
|
349
|
+
com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
|
350
|
+
|
351
|
+
com.mysql.jdbc.Util.getInstance(Util.java:387)
|
352
|
+
|
353
|
+
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:942)
|
354
|
+
|
355
|
+
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3966)
|
356
|
+
|
357
|
+
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3902)
|
358
|
+
|
359
|
+
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2526)
|
360
|
+
|
361
|
+
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2673)
|
362
|
+
|
363
|
+
com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549)
|
364
|
+
|
365
|
+
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
|
366
|
+
|
367
|
+
com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2073)
|
368
|
+
|
369
|
+
com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2009)
|
370
|
+
|
371
|
+
com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5098)
|
372
|
+
|
373
|
+
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1994)
|
374
|
+
|
375
|
+
org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:97)
|
376
|
+
|
377
|
+
org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:97)
|
378
|
+
|
379
|
+
servlet.user_edit.doPost(user_edit.java:62)
|
380
|
+
|
381
|
+
javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
|
382
|
+
|
383
|
+
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
|
384
|
+
|
385
|
+
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
|