質問編集履歴

2

追記

2016/06/21 01:56

投稿

l_l_l_l_l_l_l_l
l_l_l_l_l_l_l_l

スコア38

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

追記

2016/06/21 01:56

投稿

l_l_l_l_l_l_l_l
l_l_l_l_l_l_l_l

スコア38

test CHANGED
File without changes
test CHANGED
@@ -92,458 +92,294 @@
92
92
 
93
93
  ```
94
94
 
95
+
96
+
95
- ###jsp
97
+ ###servlet
96
98
 
97
99
  ```
98
100
 
99
- <%@ page contentType="text/html; charset=UTF-8"
100
-
101
- import="java.sql.*,javax.naming.*,javax.sql.*,java.text.*"%>
102
-
103
- <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
104
-
105
- <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
106
-
107
-
108
-
109
-
110
-
111
- <html>
112
-
113
-
114
-
115
-
116
-
117
- <sql:setDataSource var="db" driver="com.mysql.jdbc.Driver"
118
-
119
- url="jdbc:mysql://localhost/Library" user="root" password="" />
120
-
121
-
122
-
123
- <sql:query var="rs1" dataSource="${db}">
124
-
125
- select * from user
126
-
127
- </sql:query>
128
-
129
- <head>
130
-
131
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
132
-
133
-
134
-
135
- <title>ユーザ管理画面</title>
136
-
137
- </head>
138
-
139
- <body>
140
-
141
- <h2>ユーザー管理画面</h2>
142
-
143
-
144
-
145
- <form method="POST" action="user_edit">
146
-
147
- ユーザーID
148
-
149
- <select name="user_no">
150
-
151
- <c:forEach var="row" items="${rs1.rows}">
152
-
153
- <option value=${row.user_no}>${row.user_id}</option>
154
-
155
- </c:forEach>
156
-
157
- </select>
158
-
159
- <br>
160
-
161
- 名前(姓)
162
-
163
- <input type="text" name="first_name" size="30">
164
-
165
- 名前(名)
166
-
167
- <input type="text" name="last_name" size="30">
168
-
169
- <br>
170
-
171
- カナ(姓)
172
-
173
- <input type="text" name="first_name_kana" size="30">
174
-
175
- カナ(名)
176
-
177
- <input type="text" name="last_name_kana" size="30">
178
-
179
- <br>
180
-
181
- ID
182
-
183
- <input type="text" name="user_id" size="30">
184
-
185
- パスワード
186
-
187
- <input type="password" name="password" size="30">
188
-
189
- <br><br>
190
-
191
-
192
-
193
- <input style="color:white;
194
-
195
- background-color:D57200;" type="submit" value="更新"/>
196
-
197
-
198
-
199
- </form>
200
-
201
- <c:if test="${!empty requestScope['errorMessage']}">
202
-
203
- <div>${requestScope['errorMessage']}</div>
204
-
205
- </c:if>
206
-
207
- <h3>ユーザリスト</h3>
208
-
209
- <table border="1" width=70%>
210
-
211
- <tr>
212
-
213
- <th>ユーザNo</th>
214
-
215
- <th>名前(姓)</th>
216
-
217
- <th>名前(名)</th>
218
-
219
-
220
-
221
- <th>カナ(姓)</th>
222
-
223
- <th>カナ(名)</th>
224
-
225
-
226
-
227
- <th>ID</th>
228
-
229
- <th>パスワード</th>
230
-
231
- </tr>
232
-
233
- <%
234
-
235
-
236
-
237
- Connection con = null;
238
-
239
- PreparedStatement ps = null;
240
-
241
- String sql = null;
242
-
243
- ResultSet rs = null;
244
-
245
- try{
246
-
247
- InitialContext initContext = new InitialContext();
248
-
249
- DataSource ds = (DataSource) initContext.lookup("java:comp/env/jdbc/Library");
250
-
251
- con = ds.getConnection();
252
-
253
- sql = "SELECT user_no,first_name,last_name,first_name_kana,last_name_kana,user_id,password FROM user";
254
-
255
-
256
-
257
- // SELECT命令の準備
258
-
259
- ps = con.prepareStatement(sql);
260
-
261
-
262
-
263
- // UPDATE命令を実行
264
-
265
- rs = ps.executeQuery();
266
-
267
- // 結果セットの内容を順に出力
268
-
269
- while(rs.next()){
270
-
271
-
272
-
273
- %>
274
-
275
-
276
-
277
- <tr>
278
-
279
- <td height=70><%=rs.getString("user_no") %></td>
280
-
281
- <td height=70><%=rs.getString("first_name") %></td>
282
-
283
- <td height=70><%=rs.getString("last_name") %></td>
284
-
285
- <td height=70><%=rs.getString("first_name_kana") %></td>
286
-
287
- <td height=70><%=rs.getString("last_name_kana") %></td>
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
- }catch(Exception e){
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
- ###servlet
354
-
355
- ```
356
-
357
- package servlet;
358
-
359
-
360
-
361
- import java.io.IOException;
362
-
363
- import java.sql.Connection;
364
-
365
- import java.sql.PreparedStatement;
366
-
367
- import java.sql.ResultSet;
368
-
369
-
370
-
371
- import javax.naming.InitialContext;
372
-
373
- import javax.servlet.ServletException;
374
-
375
- import javax.servlet.annotation.WebServlet;
376
-
377
- import javax.servlet.http.HttpServlet;
378
-
379
- import javax.servlet.http.HttpServletRequest;
380
-
381
- import javax.servlet.http.HttpServletResponse;
382
-
383
- import javax.servlet.http.HttpSession;
384
-
385
- import javax.sql.DataSource;
386
-
387
-
388
-
389
- @WebServlet("/user_edit")
390
-
391
- public class user_edit extends HttpServlet {
392
-
393
- private static final long serialVersionUID = 1L;
394
-
395
-
396
-
397
- protected void doPost(HttpServletRequest request,
398
-
399
- HttpServletResponse response) throws ServletException, IOException {
400
-
401
- request.setCharacterEncoding("UTF-8");
402
-
403
-
404
-
405
- Connection con = null;
406
-
407
- PreparedStatement ps = null;
408
-
409
- String sql = null;
410
-
411
- ResultSet rs = null;
412
-
413
-
414
-
415
- // セッションを取得する
416
-
417
- HttpSession session = request.getSession();
418
-
419
- // 変数の初期化
420
-
421
- boolean userResult = false;
422
-
423
-
424
-
425
- if (session.getAttribute("userResult") != null) {
426
-
427
- userResult = (boolean) session.getAttribute("userResult");
428
-
429
- }
430
-
431
-
432
-
433
- if (userResult) {
434
-
435
- try {
436
-
437
- // データベースの接続を確立
438
-
439
- InitialContext initContext = new InitialContext();
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)