質問編集履歴

7

リストで返すようにコードを書きなおしましたが、リストで返したデータの取り出し方が調べてもわかりません!

2020/03/24 05:49

投稿

chimo
chimo

スコア55

test CHANGED
File without changes
test CHANGED
@@ -46,6 +46,8 @@
46
46
 
47
47
  import java.io.PrintWriter;
48
48
 
49
+ import java.util.List;
50
+
49
51
 
50
52
 
51
53
  import javax.servlet.ServletException;
@@ -92,7 +94,7 @@
92
94
 
93
95
  BusinessLogic logic_ex = new BusinessLogic();
94
96
 
95
- SurveyDto resultDto = logic_ex.executeSelectSurvey();
97
+ List<SurveyDto> resultDto = logic_ex.executeSelectSurvey();
96
98
 
97
99
 
98
100
 
@@ -136,19 +138,19 @@
136
138
 
137
139
  out.println( "<table class=\"list\" border=1 id=\"TABLE\">" ) ;
138
140
 
139
- out.println( " <tr bgcolor=\"#c0c0c0\"> ");
141
+ out.println( " <tr bgcolor=\"#c0c0c0\"> "); // trタグ:1行分の情報を表す(1行目)
140
-
142
+
141
- out.println( " <th>名前</th> ");
143
+ out.println( " <th>名前</th> "); // thタグ:見出しを表す(1列目)
142
-
144
+
143
- out.println( " <th>年齢</th> ");
145
+ out.println( " <th>年齢</th> "); // thタグ:見出しを表す(2列目)
144
-
146
+
145
- out.println( " <th>性別</th> ");
147
+ out.println( " <th>性別</th> "); // thタグ:見出しを表す(3列目)
146
-
148
+
147
- out.println( " <th>満足度</th> ");
149
+ out.println( " <th>満足度</th> "); // thタグ:見出しを表す(4列目)
148
-
150
+
149
- out.println( " <th>ご意見・ご感想</th> ");
151
+ out.println( " <th>ご意見・ご感想</th> "); // thタグ:見出しを表す(5列目)
150
-
152
+
151
- out.println( " </tr> ");
153
+ out.println( " </tr> "); // trタグ(閉じ)
152
154
 
153
155
 
154
156
 
@@ -172,7 +174,7 @@
172
174
 
173
175
 
174
176
 
175
- out.println(" <a href=\"InputSurvey\">アンケート画面へ戻る</a> ");
177
+ out.println(" <a href=\"InputSurvey\">アンケート画面へ戻る</a> "); //前の画面に戻るリンクの設定
176
178
 
177
179
 
178
180
 
@@ -198,44 +200,24 @@
198
200
 
199
201
  }
200
202
 
203
+
204
+
201
205
  ```
202
206
 
203
207
  【②】MySQLに送信するためのセレクト文
204
208
 
205
209
  ```java
206
210
 
207
- public SurveyDto doSelect() {
211
+ public List<SurveyDto> doSelect() {
208
-
209
-
210
-
211
- //JDBCドライバの相対パス
212
+
212
-
213
- //※バージョンによって変わる可能性があります(MySQL5系の場合は「com.mysql.jdbc.Driver」)
213
+
214
214
 
215
215
  String driverName = "com.mysql.cj.jdbc.Driver";
216
216
 
217
-
218
-
219
- //接続先のデータベース
220
-
221
- //※データベース名が「test_db」でない場合は該当の箇所を変更してください
222
-
223
217
  String jdbcUrl = "jdbc:mysql://localhost/test_db?characterEncoding=UTF-8&serverTimezone=JST&useSSL=false";
224
218
 
225
-
226
-
227
- //接続するユーザー名
228
-
229
- //※ユーザー名が「test_user」でない場合は該当の箇所を変更してください
230
-
231
219
  String userId = "test_user";
232
220
 
233
-
234
-
235
- //接続するユーザーのパスワード
236
-
237
- //※パスワードが「test_pass」でない場合は該当の箇所を変更してください
238
-
239
221
  String userPass = "test_pass";
240
222
 
241
223
 
@@ -252,15 +234,15 @@
252
234
 
253
235
 
254
236
 
255
- Connection con = null ; // Connection(DB接続情報)格納用変数
256
-
257
- PreparedStatement ps = null ; // PreparedStatement(SQL発行用オブジェクト)格納用変数
258
-
259
- ResultSet rs = null ; // ResultSet(SQL抽出結果)格納用変数
260
-
261
-
262
-
263
- SurveyDto dto = null;
237
+ Connection con = null ;
238
+
239
+ PreparedStatement ps = null ;
240
+
241
+ ResultSet rs = null ;
242
+
243
+
244
+
245
+ List<SurveyDto> dtoList = new ArrayList<SurveyDto>();
264
246
 
265
247
 
266
248
 
@@ -268,8 +250,6 @@
268
250
 
269
251
  con = DriverManager.getConnection(jdbcUrl, userId, userPass);
270
252
 
271
-
272
-
273
253
  //SQL文の生成(SELECT)
274
254
 
275
255
  StringBuffer buf = new StringBuffer() ;
@@ -292,33 +272,31 @@
292
272
 
293
273
 
294
274
 
295
- //PreparedStatementオブジェクトを生成&発行するSQLをセット
296
-
297
275
  ps = con.prepareStatement(buf.toString());
298
276
 
299
277
 
300
278
 
301
- //SQL文の送信&抽出結果(ResultSetオブジェクト)の取得
302
-
303
279
  rs = ps.executeQuery();
304
280
 
305
281
 
306
282
 
307
283
  //ResultSetオブジェクトから1レコード分のデータをDTOに格納
308
284
 
309
- if(rs.next()){
285
+ while(rs.next()){
310
-
286
+
311
- dto = new SurveyDto();
287
+ SurveyDto dto_list = new SurveyDto();
312
-
288
+
313
- dto.setName( rs.getString( "NAME" ) );
289
+ dto_list.setName( rs.getString( "NAME" ) );
314
-
290
+
315
- dto.setAge( rs.getInt( "AGE" ) );
291
+ dto_list.setAge( rs.getInt( "AGE" ) );
316
-
292
+
317
- dto.setSex( rs.getInt( "SEX" ) );
293
+ dto_list.setSex( rs.getInt( "SEX" ) );
318
-
294
+
319
- dto.setSatisfactionLevel( rs.getInt( "SATISFACTION_LEVEL" ) );
295
+ dto_list.setSatisfactionLevel( rs.getInt( "SATISFACTION_LEVEL" ) );
320
-
296
+
321
- dto.setMessage( rs.getString( "MESSAGE" ) );
297
+ dto_list.setMessage( rs.getString( "MESSAGE" ) );
298
+
299
+ dtoList.add(dto_list) ;
322
300
 
323
301
  }
324
302
 
@@ -334,15 +312,13 @@
334
312
 
335
313
  } finally {
336
314
 
337
-
338
-
339
315
  //ResultSetオブジェクトの接続解除
340
316
 
341
- if (rs != null) { //接続が確認できている場合のみ実施
317
+ if (rs != null) {
342
318
 
343
319
  try {
344
320
 
345
- rs.close(); //接続の解除
321
+ rs.close();
346
322
 
347
323
  } catch (SQLException e) {
348
324
 
@@ -352,15 +328,13 @@
352
328
 
353
329
  }
354
330
 
355
-
356
-
357
331
  //PreparedStatementオブジェクトの接続解除
358
332
 
359
- if (ps != null) { //接続が確認できている場合のみ実施
333
+ if (ps != null) {
360
334
 
361
335
  try {
362
336
 
363
- ps.close(); //接続の解除
337
+ ps.close();
364
338
 
365
339
  } catch (SQLException e) {
366
340
 
@@ -370,15 +344,13 @@
370
344
 
371
345
  }
372
346
 
373
-
374
-
375
347
  //Connectionオブジェクトの接続解除
376
348
 
377
- if (con != null) { //接続が確認できている場合のみ実施
349
+ if (con != null) {
378
350
 
379
351
  try {
380
352
 
381
- con.close(); //接続の解除
353
+ con.close();
382
354
 
383
355
  } catch (SQLException e) {
384
356
 
@@ -390,11 +362,7 @@
390
362
 
391
363
  }
392
364
 
393
-
394
-
395
- //抽出データを戻す
396
-
397
- return dto;
365
+     return dtoList;
398
366
 
399
367
  }
400
368
 
@@ -406,11 +374,11 @@
406
374
 
407
375
  ```java
408
376
 
409
- public SurveyDto executeSelectSurvey() {
377
+ public List<SurveyDto> executeSelectSurvey() {
410
378
 
411
379
  SurveyDao dao_ex = new SurveyDao();
412
380
 
413
- SurveyDto extractedDto = dao_ex.doSelect();
381
+ List<SurveyDto> extractedDto = dao_ex.doSelect();
414
382
 
415
383
  return extractedDto ;
416
384
 
@@ -518,4 +486,30 @@
518
486
 
519
487
  ```
520
488
 
521
- 【追記】修正依頼をうけてコードを修正しました!テーブルはブラウザに出るようになっのですが、MYSQLのデータの一番初めのデータしでてくれません。一応アンケート結果一覧なので登録されいる全てのデータを選択のでが…
489
+ 【追記】修正依頼をうけてコードを修正しました!Listでdtoを返すようにコードを書き換えましたが、リストを格納しているdtoからどうやってデータを取得すればよいわかりません。SowAllSurvey以下の部分エラーが出てしす。
490
+
491
+ ```java
492
+
493
+ //DTO内のデータを取り出す
494
+
495
+ String name_ex = resultDto.getName();
496
+
497
+ String age_ex = String.valueOf(resultDto.getAge());
498
+
499
+ String sex_ex = String.valueOf(resultDto.getSex());
500
+
501
+ String satisfactionLevel_ex = String.valueOf(resultDto.getSatisfactionLevel());
502
+
503
+ String message_ex = resultDto.getMessage();
504
+
505
+
506
+
507
+ ```
508
+
509
+ 【エラー内容】--------------------
510
+
511
+ 例)メソッドgetName()は型List<SurveyDto>で未定義です。
512
+
513
+ ーーーーーーーーーーーーーーーーーーーーーーーーーーー
514
+
515
+ SurveyDtoクラスでList<SurveyDto>で定義しろということでしょうか?でも自分なりに調べたところリストを作るときもdtoクラスはいじらなくてもよいとあったのですが…。

6

コードを修正いたしました!!

2020/03/24 05:49

投稿

chimo
chimo

スコア55

test CHANGED
File without changes
test CHANGED
@@ -18,44 +18,6 @@
18
18
 
19
19
  このうち(1)と(2)はうまくいきましたが、(3)のうまくデータを抽出してきて、アンケート入力画面からアンケート結果一覧へ画面遷移させようとするとエラーがおきてしまいます。とにかく(3)の画面遷移をうまくいくようにしたいのです、が、何が問題でうまくいかないのかさっぱりわかりません!!アリゴリズムがまちがっているのかコーディングがまちがっているのか、もしコーディングが間違っていれば正しいコードを教えてください!
20
20
 
21
- 【エラー】
22
-
23
- Type Exception Report
24
-
25
-
26
-
27
- Message null
28
-
29
-
30
-
31
- Description The server encountered an unexpected condition that prevented it from fulfilling the request.
32
-
33
-
34
-
35
- Exception
36
-
37
- java.lang.NumberFormatException: null
38
-
39
- java.lang.Integer.parseInt(Integer.java:542)
40
-
41
- java.lang.Integer.parseInt(Integer.java:615)
42
-
43
- work.SaveSurvey.doPost(SaveSurvey.java:40)
44
-
45
- work.SaveSurvey.doGet(SaveSurvey.java:26)
46
-
47
- javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
48
-
49
- javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
50
-
51
- org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
52
-
53
-
54
-
55
-
56
-
57
- Note The full stack trace of the root cause is available in the server logs.
58
-
59
21
 
60
22
 
61
23
  【各クラスで行っていること】
@@ -82,9 +44,7 @@
82
44
 
83
45
  import java.io.IOException;
84
46
 
85
- import java.util.ArrayList;
47
+ import java.io.PrintWriter;
86
-
87
- import java.util.List;
88
48
 
89
49
 
90
50
 
@@ -152,83 +112,337 @@
152
112
 
153
113
 
154
114
 
155
- //投稿内容スト
115
+ //出力用のストリームの取得
156
-
157
- List<String> postContentList = new ArrayList<String>() ;
116
+
158
-
159
- postContentList.add( name_ex ) ;
160
-
161
- postContentList.add( age_ex ) ;
162
-
163
- postContentList.add( sex_ex ) ;
164
-
165
- postContentList.add( satisfactionLevel_ex ) ;
166
-
167
- postContentList.add( message_ex ) ;
117
+ PrintWriter out = response.getWriter();
168
118
 
169
119
 
170
120
 
171
121
  //HTML文書(HTMLテーブル作成Sample画面)の出力
172
122
 
173
- System.out.println( "<html>" ) ;
174
-
175
- System.out.println( "<head>" ) ;
176
-
177
- System.out.println( "<title>アンケート回答一覧</title>" ) ;
178
-
179
- System.out.println( "</head>" ) ;
180
-
181
- System.out.println( "<body>" ) ;
182
-
183
- System.out.println( "<h2>アンケート回答一覧</h2>" ) ;
184
-
185
-
186
-
187
- System.out.println( "< table class=\"list\" border=1 id=\"TABLE\"> " ) ;
188
-
189
- System.out.println( " <tr bgcolor=\"#c0c0c0\"> "); // trタグ:1行分の情報を表す(1行目)
190
-
191
- System.out.println( " <th>名前</th> "); // thタグ:見出しを表す(1列目)
192
-
193
- System.out.println( " <th>年齢</th> "); // thタグ:見出しを表す(2列目)
194
-
195
- System.out.println( " <th>性別</th> "); // thタグ:見出しを表す(3列目)
196
-
197
- System.out.println( " <th>満足度</th> "); // thタグ:見出しを表す(4列目)
198
-
199
- System.out.println( " <th>ご意見・ご感想</th> "); // thタグ:見出しを表す(5列目)
200
-
201
- System.out.println( " </tr> "); // trタグ(閉じ)
202
-
203
-
204
-
205
- for (int i = 0; i < postContentList.size(); i++) {
206
-
207
- System.out.println(" <tr> ");
208
-
209
- System.out.println(" <td>" + postContentList.get(i) + "</td> ");
210
-
211
- System.out.println(" </tr> ");
212
-
213
-
123
+ out.println( "<html>" ) ;
124
+
125
+ out.println( "<head>" ) ;
126
+
127
+ out.println( "<title>アンケート回答一覧</title>" ) ;
128
+
129
+ out.println( "</head>" ) ;
130
+
131
+ out.println( "<body>" ) ;
132
+
133
+ out.println( "<h2>アンケート回答一覧</h2>" ) ;
134
+
135
+
136
+
137
+ out.println( "<table class=\"list\" border=1 id=\"TABLE\">" ) ;
138
+
139
+ out.println( " <tr bgcolor=\"#c0c0c0\"> ");
140
+
141
+ out.println( " <th>名前</th> ");
142
+
143
+ out.println( " <th>年齢</th> ");
144
+
145
+ out.println( " <th>性別</th> ");
146
+
147
+ out.println( " <th>満足度</th> ");
148
+
149
+ out.println( " <th>ご意見・ご感想</th> ");
150
+
151
+ out.println( " </tr> ");
152
+
153
+
154
+
155
+ out.println( "<tr> ");
156
+
157
+ out.println( " <td>" + name_ex + "</td> ");
158
+
159
+ out.println( " <td>" + age_ex + "</td> ");
160
+
161
+ out.println( " <td>" + sex_ex + "</td> ");
162
+
163
+ out.println( " <td>" + satisfactionLevel_ex + "</td> ");
164
+
165
+ out.println( " <td>" + message_ex + "</td> ");
166
+
167
+ out.println( "</tr> ");
168
+
169
+
170
+
171
+ out.println( "</table> ");
172
+
173
+
174
+
175
+ out.println(" <a href=\"InputSurvey\">アンケート画面へ戻る</a> ");
176
+
177
+
178
+
179
+ out.println( "</body> ");
180
+
181
+ out.println( "</html> ");
182
+
183
+
184
+
185
+ }
186
+
187
+
188
+
189
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
190
+
191
+ throws ServletException, IOException {
192
+
193
+ doGet(request, response);
194
+
195
+ }
196
+
197
+
198
+
199
+ }
200
+
201
+ ```
202
+
203
+ 【②】MySQLに送信するためのセレクト文
204
+
205
+ ```java
206
+
207
+ public SurveyDto doSelect() {
208
+
209
+
210
+
211
+ //JDBCドライバの相対パス
212
+
213
+ //※バージョンによって変わる可能性があります(MySQL5系の場合は「com.mysql.jdbc.Driver」)
214
+
215
+ String driverName = "com.mysql.cj.jdbc.Driver";
216
+
217
+
218
+
219
+ //接続先のデータベース
220
+
221
+ //※データベース名が「test_db」でない場合は該当の箇所を変更してください
222
+
223
+ String jdbcUrl = "jdbc:mysql://localhost/test_db?characterEncoding=UTF-8&serverTimezone=JST&useSSL=false";
224
+
225
+
226
+
227
+ //接続するユーザー名
228
+
229
+ //※ユーザー名が「test_user」でない場合は該当の箇所を変更してください
230
+
231
+ String userId = "test_user";
232
+
233
+
234
+
235
+ //接続するユーザーのパスワード
236
+
237
+ //※パスワードが「test_pass」でない場合は該当の箇所を変更してください
238
+
239
+ String userPass = "test_pass";
240
+
241
+
242
+
243
+ try {
244
+
245
+ Class.forName(driverName);
246
+
247
+ } catch (ClassNotFoundException e) {
248
+
249
+ e.printStackTrace();
250
+
251
+ }
252
+
253
+
254
+
255
+ Connection con = null ; // Connection(DB接続情報)格納用変数
256
+
257
+ PreparedStatement ps = null ; // PreparedStatement(SQL発行用オブジェクト)格納用変数
258
+
259
+ ResultSet rs = null ; // ResultSet(SQL抽出結果)格納用変数
260
+
261
+
262
+
263
+ SurveyDto dto = null;
264
+
265
+
266
+
267
+ try {
268
+
269
+ con = DriverManager.getConnection(jdbcUrl, userId, userPass);
270
+
271
+
272
+
273
+ //SQL文の生成(SELECT)
274
+
275
+ StringBuffer buf = new StringBuffer() ;
276
+
277
+ buf.append(" SELECT ");
278
+
279
+ buf.append(" NAME , ");
280
+
281
+ buf.append(" AGE , ");
282
+
283
+ buf.append(" SEX , ");
284
+
285
+ buf.append(" SATISFACTION_LEVEL , ");
286
+
287
+ buf.append(" MESSAGE ");
288
+
289
+ buf.append(" FROM ");
290
+
291
+ buf.append(" SURVEY ");
292
+
293
+
294
+
295
+ //PreparedStatementオブジェクトを生成&発行するSQLをセット
296
+
297
+ ps = con.prepareStatement(buf.toString());
298
+
299
+
300
+
301
+ //SQL文の送信&抽出結果(ResultSetオブジェクト)の取得
302
+
303
+ rs = ps.executeQuery();
304
+
305
+
306
+
307
+ //ResultSetオブジェクトから1レコード分のデータをDTOに格納
308
+
309
+ if(rs.next()){
310
+
311
+ dto = new SurveyDto();
312
+
313
+ dto.setName( rs.getString( "NAME" ) );
314
+
315
+ dto.setAge( rs.getInt( "AGE" ) );
316
+
317
+ dto.setSex( rs.getInt( "SEX" ) );
318
+
319
+ dto.setSatisfactionLevel( rs.getInt( "SATISFACTION_LEVEL" ) );
320
+
321
+ dto.setMessage( rs.getString( "MESSAGE" ) );
322
+
323
+ }
324
+
325
+
326
+
327
+ } catch (SQLException e) {
328
+
329
+ e.printStackTrace();
330
+
331
+
332
+
333
+
334
+
335
+ } finally {
336
+
337
+
338
+
339
+ //ResultSetオブジェクトの接続解除
340
+
341
+ if (rs != null) { //接続が確認できている場合のみ実施
342
+
343
+ try {
344
+
345
+ rs.close(); //接続の解除
346
+
347
+ } catch (SQLException e) {
348
+
349
+ e.printStackTrace();
350
+
351
+ }
352
+
353
+ }
354
+
355
+
356
+
357
+ //PreparedStatementオブジェクトの接続解除
358
+
359
+ if (ps != null) { //接続が確認できている場合のみ実施
360
+
361
+ try {
362
+
363
+ ps.close(); //接続の解除
364
+
365
+ } catch (SQLException e) {
366
+
367
+ e.printStackTrace();
368
+
369
+ }
370
+
371
+ }
372
+
373
+
374
+
375
+ //Connectionオブジェクトの接続解除
376
+
377
+ if (con != null) { //接続が確認できている場合のみ実施
378
+
379
+ try {
380
+
381
+ con.close(); //接続の解除
382
+
383
+ } catch (SQLException e) {
384
+
385
+ e.printStackTrace();
386
+
387
+ }
388
+
389
+ }
390
+
391
+ }
392
+
393
+
394
+
395
+ //抽出データを戻す
396
+
397
+ return dto;
214
398
 
215
399
  }
216
400
 
217
401
 
218
402
 
403
+ ```
404
+
405
+ 【追記:BusinessLogicクラスのコード一部抜粋】
406
+
407
+ ```java
408
+
409
+ public SurveyDto executeSelectSurvey() {
410
+
411
+ SurveyDao dao_ex = new SurveyDao();
412
+
413
+ SurveyDto extractedDto = dao_ex.doSelect();
414
+
415
+ return extractedDto ;
416
+
417
+ }
418
+
419
+ ```
420
+
421
+
422
+
423
+ 【追記:Savesurveyクラスのコード】
424
+
425
+ ```java
426
+
427
+ public class SaveSurvey extends HttpServlet {
428
+
429
+ private static final long serialVersionUID = 1L;
430
+
431
+
432
+
433
+ public SaveSurvey() {
434
+
435
+ super();
436
+
437
+ }
438
+
439
+
440
+
219
- System.out.println(" </table> ");
441
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
220
-
221
-
222
-
223
- System.out.println(" <a href=\"InputSurvey\">アンケート画面へ戻る</a> "); //前の画面に戻るリンクの設定
442
+
224
-
225
-
226
-
227
- System.out.println( "</body> ");
443
+ throws ServletException, IOException {
228
-
444
+
229
- System.out.println( "</html> ");
445
+ doPost(request, response);
230
-
231
-
232
446
 
233
447
  }
234
448
 
@@ -238,332 +452,70 @@
238
452
 
239
453
  throws ServletException, IOException {
240
454
 
455
+
456
+
457
+ response.setContentType("text/html;charset=UTF-8");
458
+
459
+ request.setCharacterEncoding("UTF-8");
460
+
461
+
462
+
463
+ //リクエストパラメータを取得
464
+
465
+ String name = request.getParameter("NAME");
466
+
467
+ int age = Integer.parseInt(request.getParameter("AGE"));
468
+
469
+ int sex = Integer.parseInt(request.getParameter("SEX")) ;
470
+
471
+ int satisfactionLevel = Integer.parseInt(request.getParameter("SATISFACTION_LEVEL")) ;
472
+
473
+ String message = request.getParameter("MESSAGE");
474
+
475
+
476
+
477
+ //アンケートデータ(SurveyDto型)の作成
478
+
479
+ SurveyDto dto = new SurveyDto();
480
+
481
+ dto.setName( name );
482
+
483
+ dto.setAge( age );
484
+
485
+ dto.setSex( sex );
486
+
487
+ dto.setSatisfactionLevel( satisfactionLevel );
488
+
241
- doGet(request, response);
489
+ dto.setMessage( message );
490
+
242
-
491
+ dto.setTime( new Timestamp(System.currentTimeMillis()) );
492
+
493
+ //アンケートデータをDBに登録
494
+
495
+ BusinessLogic logic = new BusinessLogic();
496
+
497
+ boolean succesInsert = logic.executeInsertSurvey(dto);
498
+
499
+
500
+
501
+ //DB操作の成功/失敗に応じて表示させる画面を振り分ける
502
+
503
+ if (succesInsert) {
504
+
505
+ response.sendRedirect("htmls/finish.html");
506
+
507
+ } else {
508
+
509
+ response.sendRedirect("htmls/error.html");
510
+
243
- }
511
+ }
512
+
244
-
513
+ }
245
-
246
514
 
247
515
  }
248
516
 
517
+
518
+
249
519
  ```
250
520
 
251
- 【②】MySQLに送信するためのセレクト文
252
-
253
- ```java
254
-
255
- public SurveyDto doSelect() {
256
-
257
-
258
-
259
- //JDBCドライバの相対パス
260
-
261
- //※バージョンによって変わる可能性があります(MySQL5系の場合は「com.mysql.jdbc.Driver」)
262
-
263
- String driverName = "com.mysql.cj.jdbc.Driver";
264
-
265
-
266
-
267
- //接続先のデータベース
268
-
269
- //※データベース名が「test_db」でない場合は該当の箇所を変更してください
270
-
271
- String jdbcUrl = "jdbc:mysql://localhost/test_db?characterEncoding=UTF-8&serverTimezone=JST&useSSL=false";
272
-
273
-
274
-
275
- //接続するユーザー名
276
-
277
- //※ユーザー名が「test_user」でない場合は該当の箇所を変更してください
278
-
279
- String userId = "test_user";
280
-
281
-
282
-
283
- //接続するユーザーのパスワード
284
-
285
- //※パスワードが「test_pass」でない場合は該当の箇所を変更してください
286
-
287
- String userPass = "test_pass";
288
-
289
-
290
-
291
- try {
292
-
293
- Class.forName(driverName);
294
-
295
- } catch (ClassNotFoundException e) {
296
-
297
- e.printStackTrace();
298
-
299
- }
300
-
301
-
302
-
303
- Connection con = null ; // Connection(DB接続情報)格納用変数
304
-
305
- PreparedStatement ps = null ; // PreparedStatement(SQL発行用オブジェクト)格納用変数
306
-
307
- ResultSet rs = null ; // ResultSet(SQL抽出結果)格納用変数
308
-
309
-
310
-
311
- SurveyDto dto = null;
312
-
313
-
314
-
315
- try {
316
-
317
- con = DriverManager.getConnection(jdbcUrl, userId, userPass);
318
-
319
-
320
-
321
- //SQL文の生成(SELECT)
322
-
323
- StringBuffer buf = new StringBuffer() ;
324
-
325
- buf.append(" SELECT ");
326
-
327
- buf.append(" NAME , ");
328
-
329
- buf.append(" AGE , ");
330
-
331
- buf.append(" SEX , ");
332
-
333
- buf.append(" SATISFACTION_LEVEL , ");
334
-
335
- buf.append(" MESSAGE ");
336
-
337
- buf.append(" FROM ");
338
-
339
- buf.append(" SURVEY ");
340
-
341
-
342
-
343
- //PreparedStatementオブジェクトを生成&発行するSQLをセット
344
-
345
- ps = con.prepareStatement(buf.toString());
346
-
347
-
348
-
349
- //SQL文の送信&抽出結果(ResultSetオブジェクト)の取得
350
-
351
- rs = ps.executeQuery();
352
-
353
-
354
-
355
- //ResultSetオブジェクトから1レコード分のデータをDTOに格納
356
-
357
- if(rs.next()){
358
-
359
- dto = new SurveyDto();
360
-
361
- dto.setName( rs.getString( "name" ) );
362
-
363
- dto.setAge( rs.getInt( "age" ) );
364
-
365
- dto.setSex( rs.getInt( "sex" ) );
366
-
367
- dto.setSatisfactionLevel( rs.getInt( "satisfactionLevel" ) );
368
-
369
- dto.setMessage( rs.getString( "message" ) );
370
-
371
- }
372
-
373
-
374
-
375
- } catch (SQLException e) {
376
-
377
- e.printStackTrace();
378
-
379
-
380
-
381
-
382
-
383
- } finally {
384
-
385
-
386
-
387
- //ResultSetオブジェクトの接続解除
388
-
389
- if (rs != null) { //接続が確認できている場合のみ実施
390
-
391
- try {
392
-
393
- rs.close(); //接続の解除
394
-
395
- } catch (SQLException e) {
396
-
397
- e.printStackTrace();
398
-
399
- }
400
-
401
- }
402
-
403
-
404
-
405
- //PreparedStatementオブジェクトの接続解除
406
-
407
- if (ps != null) { //接続が確認できている場合のみ実施
408
-
409
- try {
410
-
411
- ps.close(); //接続の解除
412
-
413
- } catch (SQLException e) {
414
-
415
- e.printStackTrace();
416
-
417
- }
418
-
419
- }
420
-
421
-
422
-
423
- //Connectionオブジェクトの接続解除
424
-
425
- if (con != null) { //接続が確認できている場合のみ実施
426
-
427
- try {
428
-
429
- con.close(); //接続の解除
430
-
431
- } catch (SQLException e) {
432
-
433
- e.printStackTrace();
434
-
435
- }
436
-
437
- }
438
-
439
- }
440
-
441
-
442
-
443
- //抽出データを戻す
444
-
445
- return dto;
446
-
447
- }
448
-
449
-
450
-
451
- ```
452
-
453
- 【追記:BusinessLogicクラスのコード一部抜粋】
454
-
455
- ```java
456
-
457
- public SurveyDto executeSelectSurvey() {
458
-
459
- SurveyDao dao_ex = new SurveyDao();
460
-
461
- SurveyDto extractedDto = dao_ex.doSelect();
462
-
463
- return extractedDto ;
464
-
465
- }
466
-
467
- ```
468
-
469
-
470
-
471
- 【追記:Savesurveyクラスのコード】
472
-
473
- ```java
474
-
475
- public class SaveSurvey extends HttpServlet {
476
-
477
- private static final long serialVersionUID = 1L;
478
-
479
-
480
-
481
- public SaveSurvey() {
482
-
483
- super();
484
-
485
- }
486
-
487
-
488
-
489
- protected void doGet(HttpServletRequest request, HttpServletResponse response)
490
-
491
- throws ServletException, IOException {
492
-
493
- doPost(request, response);
494
-
495
- }
496
-
497
-
498
-
499
- protected void doPost(HttpServletRequest request, HttpServletResponse response)
500
-
501
- throws ServletException, IOException {
502
-
503
-
504
-
505
- response.setContentType("text/html;charset=UTF-8");
506
-
507
- request.setCharacterEncoding("UTF-8");
508
-
509
-
510
-
511
- //リクエストパラメータを取得
512
-
513
- String name = request.getParameter("NAME");
514
-
515
- int age = Integer.parseInt(request.getParameter("AGE"));
516
-
517
- int sex = Integer.parseInt(request.getParameter("SEX")) ;
518
-
519
- int satisfactionLevel = Integer.parseInt(request.getParameter("SATISFACTION_LEVEL")) ;
521
+ 【追記】修正依頼をうけてコードを修正しました!テーブルはブラウザに出るようになったのですが、MYSQLのデータの一番初めのデータしかでてくれません。一応アンケート結果一覧なので登録されている全てのデータを選択したいのですが…。
520
-
521
- String message = request.getParameter("MESSAGE");
522
-
523
-
524
-
525
- //アンケートデータ(SurveyDto型)の作成
526
-
527
- SurveyDto dto = new SurveyDto();
528
-
529
- dto.setName( name );
530
-
531
- dto.setAge( age );
532
-
533
- dto.setSex( sex );
534
-
535
- dto.setSatisfactionLevel( satisfactionLevel );
536
-
537
- dto.setMessage( message );
538
-
539
- dto.setTime( new Timestamp(System.currentTimeMillis()) );
540
-
541
- //アンケートデータをDBに登録
542
-
543
- BusinessLogic logic = new BusinessLogic();
544
-
545
- boolean succesInsert = logic.executeInsertSurvey(dto);
546
-
547
-
548
-
549
- //DB操作の成功/失敗に応じて表示させる画面を振り分ける
550
-
551
- if (succesInsert) {
552
-
553
- response.sendRedirect("htmls/finish.html");
554
-
555
- } else {
556
-
557
- response.sendRedirect("htmls/error.html");
558
-
559
- }
560
-
561
- }
562
-
563
- }
564
-
565
-
566
-
567
- ```
568
-
569
- 現時点でEclipse上になんのエラーマークもないです。ですが、アンケート一覧が表示されません...。どうすればよいのか...。

5

Savesurveyクラスのコードを追加しました

2020/03/24 03:25

投稿

chimo
chimo

スコア55

test CHANGED
File without changes
test CHANGED
@@ -466,4 +466,104 @@
466
466
 
467
467
  ```
468
468
 
469
+
470
+
471
+ 【追記:Savesurveyクラスのコード】
472
+
473
+ ```java
474
+
475
+ public class SaveSurvey extends HttpServlet {
476
+
477
+ private static final long serialVersionUID = 1L;
478
+
479
+
480
+
481
+ public SaveSurvey() {
482
+
483
+ super();
484
+
485
+ }
486
+
487
+
488
+
489
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
490
+
491
+ throws ServletException, IOException {
492
+
493
+ doPost(request, response);
494
+
495
+ }
496
+
497
+
498
+
499
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
500
+
501
+ throws ServletException, IOException {
502
+
503
+
504
+
505
+ response.setContentType("text/html;charset=UTF-8");
506
+
507
+ request.setCharacterEncoding("UTF-8");
508
+
509
+
510
+
511
+ //リクエストパラメータを取得
512
+
513
+ String name = request.getParameter("NAME");
514
+
515
+ int age = Integer.parseInt(request.getParameter("AGE"));
516
+
517
+ int sex = Integer.parseInt(request.getParameter("SEX")) ;
518
+
519
+ int satisfactionLevel = Integer.parseInt(request.getParameter("SATISFACTION_LEVEL")) ;
520
+
521
+ String message = request.getParameter("MESSAGE");
522
+
523
+
524
+
525
+ //アンケートデータ(SurveyDto型)の作成
526
+
527
+ SurveyDto dto = new SurveyDto();
528
+
529
+ dto.setName( name );
530
+
531
+ dto.setAge( age );
532
+
533
+ dto.setSex( sex );
534
+
535
+ dto.setSatisfactionLevel( satisfactionLevel );
536
+
537
+ dto.setMessage( message );
538
+
539
+ dto.setTime( new Timestamp(System.currentTimeMillis()) );
540
+
541
+ //アンケートデータをDBに登録
542
+
543
+ BusinessLogic logic = new BusinessLogic();
544
+
545
+ boolean succesInsert = logic.executeInsertSurvey(dto);
546
+
547
+
548
+
549
+ //DB操作の成功/失敗に応じて表示させる画面を振り分ける
550
+
551
+ if (succesInsert) {
552
+
553
+ response.sendRedirect("htmls/finish.html");
554
+
555
+ } else {
556
+
557
+ response.sendRedirect("htmls/error.html");
558
+
559
+ }
560
+
561
+ }
562
+
563
+ }
564
+
565
+
566
+
567
+ ```
568
+
469
569
  現時点でEclipse上になんのエラーマークもないです。ですが、アンケート一覧が表示されません...。どうすればよいのか...。

4

もう一度考え直してコードを全体的に書き換えました!!

2020/03/24 01:11

投稿

chimo
chimo

スコア55

test CHANGED
File without changes
test CHANGED
@@ -18,9 +18,7 @@
18
18
 
19
19
  このうち(1)と(2)はうまくいきましたが、(3)のうまくデータを抽出してきて、アンケート入力画面からアンケート結果一覧へ画面遷移させようとするとエラーがおきてしまいます。とにかく(3)の画面遷移をうまくいくようにしたいのです、が、何が問題でうまくいかないのかさっぱりわかりません!!アリゴリズムがまちがっているのかコーディングがまちがっているのか、もしコーディングが間違っていれば正しいコードを教えてください!
20
20
 
21
- 【エラー内容
21
+ 【エラー】
22
-
23
- HTTP Status 500 – Internal Server Error
24
22
 
25
23
  Type Exception Report
26
24
 
@@ -58,8 +56,6 @@
58
56
 
59
57
  Note The full stack trace of the root cause is available in the server logs.
60
58
 
61
- Apache Tomcat/8.5.51
62
-
63
59
 
64
60
 
65
61
  【各クラスで行っていること】
@@ -102,16 +98,6 @@
102
98
 
103
99
 
104
100
 
105
- /**----------------------------------------------------------------------*
106
-
107
- *■■■ShowAllSurveyクラス■■■
108
-
109
- *概要:サーブレット
110
-
111
- *詳細:HTML文書(回答入力画面の結果)を出力する。
112
-
113
- *----------------------------------------------------------------------**/
114
-
115
101
  public class ShowAllSurvey extends HttpServlet {
116
102
 
117
103
  private static final long serialVersionUID = 1L;
@@ -142,25 +128,27 @@
142
128
 
143
129
 
144
130
 
145
- //リクエストパラメータを取得
146
-
147
- String name = request.getParameter("NAME"); //リクエストパラメータ(NAME)
148
-
149
- String age = request.getParameter("AGE"); //リクエストパラメータ(AGE)
150
-
151
- String sex = request.getParameter("SEX"); //リクエストパラメータ(SEX)
152
-
153
- String satisfactionLevel = request.getParameter("SATISFACTION_LEVEL") ; //リクエストパラメータ(SATISFACTION_LEVEL)
154
-
155
- String message = request.getParameter("MESSAGE"); //リクエストパラメータ(MESSAGE)
156
-
157
-
158
-
159
131
  //ビジネスロジックを呼び出す
160
132
 
161
133
  BusinessLogic logic_ex = new BusinessLogic();
162
134
 
163
- logic_ex.executeSelectSurvey();
135
+ SurveyDto resultDto = logic_ex.executeSelectSurvey();
136
+
137
+
138
+
139
+
140
+
141
+ //DTO内のデータを取り出す
142
+
143
+ String name_ex = resultDto.getName();
144
+
145
+ String age_ex = String.valueOf(resultDto.getAge());
146
+
147
+ String sex_ex = String.valueOf(resultDto.getSex());
148
+
149
+ String satisfactionLevel_ex = String.valueOf(resultDto.getSatisfactionLevel());
150
+
151
+ String message_ex = resultDto.getMessage();
164
152
 
165
153
 
166
154
 
@@ -168,15 +156,15 @@
168
156
 
169
157
  List<String> postContentList = new ArrayList<String>() ;
170
158
 
171
- postContentList.add( name ) ;
159
+ postContentList.add( name_ex ) ;
172
-
160
+
173
- postContentList.add( age ) ;
161
+ postContentList.add( age_ex ) ;
174
-
162
+
175
- postContentList.add( sex ) ;
163
+ postContentList.add( sex_ex ) ;
176
-
164
+
177
- postContentList.add( satisfactionLevel ) ;
165
+ postContentList.add( satisfactionLevel_ex ) ;
178
-
166
+
179
- postContentList.add( message ) ;
167
+ postContentList.add( message_ex ) ;
180
168
 
181
169
 
182
170
 
@@ -258,25 +246,13 @@
258
246
 
259
247
  }
260
248
 
261
-
262
-
263
249
  ```
264
250
 
265
251
  【②】MySQLに送信するためのセレクト文
266
252
 
267
253
  ```java
268
254
 
269
- public static String COMMA = ","; //コンマ(定数)
270
-
271
- public boolean doSelect() {
255
+ public SurveyDto doSelect() {
272
-
273
-
274
-
275
- //-------------------------------------------
276
-
277
- //データベースへの接続情報
278
-
279
- //-------------------------------------------
280
256
 
281
257
 
282
258
 
@@ -312,15 +288,9 @@
312
288
 
313
289
 
314
290
 
315
- //-------------------------------------------
316
-
317
- //① JDBCドライバのロード
318
-
319
- //-------------------------------------------
320
-
321
291
  try {
322
292
 
323
- Class.forName(driverName); //JDBCドライバをロード&接続先として指定
293
+ Class.forName(driverName);
324
294
 
325
295
  } catch (ClassNotFoundException e) {
326
296
 
@@ -330,42 +300,24 @@
330
300
 
331
301
 
332
302
 
333
-
334
-
335
- //JDBCの接続に使用するオブジェクトを宣言
336
-
337
- //※finallyブロックでも扱うためtryブロック内で宣言してはいけないことに注意
338
-
339
303
  Connection con = null ; // Connection(DB接続情報)格納用変数
340
304
 
341
305
  PreparedStatement ps = null ; // PreparedStatement(SQL発行用オブジェクト)格納用変数
342
306
 
343
307
  ResultSet rs = null ; // ResultSet(SQL抽出結果)格納用変数
344
308
 
309
+
310
+
345
- boolean isSuccess = true ;
311
+ SurveyDto dto = null;
346
312
 
347
313
 
348
314
 
349
315
  try {
350
316
 
351
- //-------------------------------------------
352
-
353
- // ②接続の確立(Connectionオブジェクトの取得)
354
-
355
- //-------------------------------------------
356
-
357
317
  con = DriverManager.getConnection(jdbcUrl, userId, userPass);
358
318
 
359
319
 
360
320
 
361
- //-------------------------------------------
362
-
363
- // ③SQL文の送信 & ④抽出結果の取得
364
-
365
- //-------------------------------------------
366
-
367
-
368
-
369
321
  //SQL文の生成(SELECT)
370
322
 
371
323
  StringBuffer buf = new StringBuffer() ;
@@ -400,77 +352,45 @@
400
352
 
401
353
 
402
354
 
403
- //ResultSetオブジェクトから1レコードずつデータを取得&加工&表示する
355
+ //ResultSetオブジェクトから1レコード分のデータをDTOに格納
404
-
356
+
405
- while (rs.next()) {
357
+ if(rs.next()){
406
-
407
-
408
-
409
- //1レコード分のデータを取得&加工(各カラムをコンマ綴りで結合)
358
+
410
-
411
- StringBuffer rsbuf = new StringBuffer();
359
+ dto = new SurveyDto();
412
-
360
+
413
- rsbuf.append(rs.getString("name"));
361
+ dto.setName( rs.getString( "name" ) );
414
-
415
- rsbuf.append(COMMA);
362
+
416
-
417
- rsbuf.append(rs.getString("age"));
363
+ dto.setAge( rs.getInt( "age" ) );
418
-
419
- rsbuf.append(COMMA);
364
+
420
-
421
- rsbuf.append(rs.getString("sex"));
365
+ dto.setSex( rs.getInt( "sex" ) );
422
-
423
- rsbuf.append(COMMA);
366
+
424
-
425
- rsbuf.append(rs.getString("satisfaction_level"));
367
+ dto.setSatisfactionLevel( rs.getInt( "satisfactionLevel" ) );
426
-
427
- rsbuf.append(COMMA);
368
+
428
-
429
- rsbuf.append(rs.getString("message"));
369
+ dto.setMessage( rs.getString( "message" ) );
430
-
431
-
432
-
433
- //加工作成した1レコード分のデータを表示
434
-
435
- System.out.println(rsbuf.toString());
436
370
 
437
371
  }
438
372
 
439
373
 
440
374
 
441
- //SQL文の実行
442
-
443
- ps.executeUpdate();
444
-
445
-
446
-
447
375
  } catch (SQLException e) {
448
376
 
449
377
  e.printStackTrace();
450
378
 
451
379
 
452
380
 
453
- //実行結果を例外発生として更新
454
-
455
- isSuccess = false ;
456
-
457
381
 
458
382
 
459
383
  } finally {
460
384
 
461
- //-------------------------------------------
385
+
462
-
386
+
463
- //トランザクション終了
387
+ //ResultSetオブジェクトの接続解除
464
-
465
- //-------------------------------------------
388
+
466
-
467
- if(isSuccess){
468
-
469
- //明示的にコミットを実施
389
+ if (rs != null) { //接続が確認できている場合のみ実施
470
390
 
471
391
  try {
472
392
 
473
- con.commit();
393
+ rs.close(); //接続の解除
474
394
 
475
395
  } catch (SQLException e) {
476
396
 
@@ -478,15 +398,17 @@
478
398
 
479
399
  }
480
400
 
481
-
482
-
483
- }else{
401
+ }
484
-
402
+
403
+
404
+
485
- //明示的にロールバッを実施
405
+ //PreparedStatementオブジェトの接続解除
406
+
407
+ if (ps != null) { //接続が確認できている場合のみ実施
486
408
 
487
409
  try {
488
410
 
489
- con.rollback();
411
+ ps.close(); //接続の解除
490
412
 
491
413
  } catch (SQLException e) {
492
414
 
@@ -498,21 +420,13 @@
498
420
 
499
421
 
500
422
 
501
- //-------------------------------------------
502
-
503
- //接続の解除
504
-
505
- //-------------------------------------------
506
-
507
-
508
-
509
- //PreparedStatementオブジェクトの接続解除
423
+ //Connectionオブジェクトの接続解除
510
-
424
+
511
- if (ps != null) { //接続が確認できている場合のみ実施
425
+ if (con != null) { //接続が確認できている場合のみ実施
512
426
 
513
427
  try {
514
428
 
515
- ps.close(); //接続の解除
429
+ con.close(); //接続の解除
516
430
 
517
431
  } catch (SQLException e) {
518
432
 
@@ -522,56 +436,34 @@
522
436
 
523
437
  }
524
438
 
525
-
526
-
527
- //Connectionオブジェクトの接続解除
528
-
529
- if (con != null) { //接続が確認できている場合のみ実施
530
-
531
- try {
532
-
533
- con.close(); //接続の解除
534
-
535
- } catch (SQLException e) {
536
-
537
- e.printStackTrace();
538
-
539
- }
540
-
541
- }
542
-
543
-
544
-
545
439
  }
546
440
 
547
441
 
548
442
 
549
- //実行結果
443
+ //抽出データ
550
-
444
+
551
- return isSuccess;
445
+ return dto;
552
446
 
553
447
  }
554
448
 
555
449
 
556
450
 
557
-
451
+ ```
452
+
453
+ 【追記:BusinessLogicクラスのコード一部抜粋】
454
+
455
+ ```java
456
+
457
+ public SurveyDto executeSelectSurvey() {
458
+
459
+ SurveyDao dao_ex = new SurveyDao();
460
+
461
+ SurveyDto extractedDto = dao_ex.doSelect();
462
+
463
+ return extractedDto ;
558
464
 
559
465
  }
560
466
 
561
-
562
-
563
467
  ```
564
468
 
565
- 【追記:doSelectメソッド呼び出し元:BusinessLogicラス中身の一部抜粋】
469
+ 現時点でEclipse上になんエラーマーもないです。ですが、アンケート一覧が表示されません...。どうすればよいか...。
566
-
567
- ```
568
-
569
- public void executeSelectSurvey() {
570
-
571
- SurveyDao dao_Ex = new SurveyDao();
572
-
573
- dao_Ex.doSelect();
574
-
575
- }
576
-
577
- ```

3

誤字

2020/03/23 13:02

投稿

chimo
chimo

スコア55

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- 複数のクラスが複雑に絡んでいるのでやりたいことを順番立てて箇条書きにしたいと思います。複数のクラスにたくさんコードを書いたのですべてここに乗せると字数が足りなくなってしまいますので、【①】javaでHTMLを使ってブラウザに表示させるためのコードを書いたクラス全体と、【②】MySQLに送信するためのセレクト文、のみここに乗せたいと思います。ほかは追記で頂いた場合コードを載せたいと思いますので、コメントお願いします。
1
+ 複数のクラスが複雑に絡んでいるのでやりたいことを順番立てて箇条書きにしたいと思います。複数のクラスにたくさんコードを書いたのですべてここに乗せると字数が足りなくなってしまいますので、【①】javaでHTMLを使ってブラウザに表示させるためのコードを書いたクラス全体と、【②】MySQLに送信するためのセレクト文、のみここに乗せたいと思います。ほかは追記で頂いた場合コードをコメント欄に載せようかと思いますので、コメントお願いします。
2
2
 
3
3
 
4
4
 

2

doSelectの呼び出し元です

2020/03/23 06:14

投稿

chimo
chimo

スコア55

test CHANGED
File without changes
test CHANGED
@@ -561,3 +561,17 @@
561
561
 
562
562
 
563
563
  ```
564
+
565
+ 【追記:doSelectメソッドの呼び出し元:BusinessLogicクラスの中身の一部抜粋】
566
+
567
+ ```
568
+
569
+ public void executeSelectSurvey() {
570
+
571
+ SurveyDao dao_Ex = new SurveyDao();
572
+
573
+ dao_Ex.doSelect();
574
+
575
+ }
576
+
577
+ ```

1

自分のしてもらいたいことを明示しました

2020/03/23 06:12

投稿

chimo
chimo

スコア55

test CHANGED
File without changes
test CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
 
18
18
 
19
- このうち(1)と(2)はうまくいきましたが、(3)のうまくデータを抽出してきて、アンケート入力画面からアンケート結果一覧へ画面遷移させようとするとエラーがおきてしまいます。
19
+ このうち(1)と(2)はうまくいきましたが、(3)のうまくデータを抽出してきて、アンケート入力画面からアンケート結果一覧へ画面遷移させようとするとエラーがおきてしまいます。とにかく(3)の画面遷移をうまくいくようにしたいのです、が、何が問題でうまくいかないのかさっぱりわかりません!!アリゴリズムがまちがっているのかコーディングがまちがっているのか、もしコーディングが間違っていれば正しいコードを教えてください!
20
20
 
21
21
  【エラー内容】
22
22