質問編集履歴
2
削除された内容の復元を行いました
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,7 +1,345 @@
|
|
1
|
+
Javaの問題が分からないので教えてください。
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
EmployeeController①〜④
|
6
|
+
|
1
|
-
|
7
|
+
EmployeeService②〜⑧
|
2
|
-
|
8
|
+
|
3
|
-
|
9
|
+
SQLのカラム名は
|
4
|
-
|
5
|
-
|
6
|
-
|
10
|
+
|
7
|
-
|
11
|
+
・id
|
12
|
+
|
13
|
+
・password
|
14
|
+
|
15
|
+
・name
|
16
|
+
|
17
|
+
・comment
|
18
|
+
|
19
|
+
・login_time
|
20
|
+
|
21
|
+
```EmploBean
|
22
|
+
|
23
|
+
public class EmployeeBean {
|
24
|
+
|
25
|
+
private String Id;
|
26
|
+
|
27
|
+
private String PassWord;
|
28
|
+
|
29
|
+
private String Name;
|
30
|
+
|
31
|
+
private String Comment;
|
32
|
+
|
33
|
+
private String Login_Time;
|
34
|
+
|
35
|
+
public void setId(String Id) {
|
36
|
+
|
37
|
+
this.Id = Id;
|
38
|
+
|
39
|
+
}
|
40
|
+
|
41
|
+
public String Id() {
|
42
|
+
|
43
|
+
return Id;
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
public void setPassWord(String PassWord) {
|
48
|
+
|
49
|
+
this.PassWord = PassWord;
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
public String getPassWord() {
|
54
|
+
|
55
|
+
return PassWord;
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
public void setName(String Name) {
|
60
|
+
|
61
|
+
this.Name = Name;
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
public String getName() {
|
66
|
+
|
67
|
+
return Name;
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
public void setLogin_Time(String Login_Time) {
|
72
|
+
|
73
|
+
this.Login_Time = Login_Time;
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
public String getLogin_Time() {
|
78
|
+
|
79
|
+
return Login_Time;
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
public void setComment(String Comment) {
|
84
|
+
|
85
|
+
this.Comment = Comment;
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
public String getComment() {
|
90
|
+
|
91
|
+
return Comment;
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
```
|
98
|
+
|
99
|
+
```EmployeeController
|
100
|
+
|
101
|
+
public class EmployeeController extends HttpServlet {
|
102
|
+
|
103
|
+
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
104
|
+
|
105
|
+
throws ServletException, IOException {
|
106
|
+
|
107
|
+
try {
|
108
|
+
|
109
|
+
// 問① index.htmlから送信されたIDとPassWordの値を取得できるように修正してください。
|
110
|
+
|
111
|
+
String id = request.getParameter("id");
|
112
|
+
|
113
|
+
String password = request.getParameter("pass");
|
114
|
+
|
115
|
+
/*
|
116
|
+
|
117
|
+
* IDとPassWordと元に、社員情報を検索する関数の呼び出し、結果をJSPに渡す処理
|
118
|
+
|
119
|
+
* ※ EmployeeBeanとEmployeeServiceをimportするのを忘れないでください。
|
120
|
+
|
121
|
+
*/
|
122
|
+
|
123
|
+
// 問② EmployeeServiceクラスをインスタンス化してください。
|
124
|
+
|
125
|
+
EmployeeService emps = new EmployeeService();
|
126
|
+
|
127
|
+
// 問③ EmployeeBeanに、EmployeeServiceよりsearch関数を呼び出し、返り値を格納してください。
|
128
|
+
|
129
|
+
emps.search("postgres", "otikuyj");
|
130
|
+
|
131
|
+
// 問④ [null]に適切な引数をセットしてください。
|
132
|
+
|
133
|
+
request.setAttribute("EmployeeBean", id);
|
134
|
+
|
135
|
+
} catch (Exception e) {
|
136
|
+
|
137
|
+
e.printStackTrace();
|
138
|
+
|
139
|
+
} finally {
|
140
|
+
|
141
|
+
ServletContext context = this.getServletContext();
|
142
|
+
|
143
|
+
RequestDispatcher dispatcher = context.getRequestDispatcher("/index.jsp");
|
144
|
+
|
145
|
+
dispatcher.forward(request, response);
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
```
|
154
|
+
|
155
|
+
```EmployeeService
|
156
|
+
|
157
|
+
public class EmployeeService {
|
158
|
+
|
159
|
+
// 問① 接続情報を記述してください
|
160
|
+
|
161
|
+
/** ドライバーのクラス名 */
|
162
|
+
|
163
|
+
private static final String POSTGRES_DRIVER = "org.postgresql.Driver";
|
164
|
+
|
165
|
+
/**
|
166
|
+
|
167
|
+
* ・JDMC接続先情報
|
168
|
+
|
169
|
+
* ポート番号(5432, 5433など)は個人で異なる可能性があります。
|
170
|
+
|
171
|
+
* 念の為、pgAdminにて対象のpostgreSQLバージョンよりメニューを開き、[プロパティ] -> [接続] を確認してください
|
172
|
+
|
173
|
+
*/
|
174
|
+
|
175
|
+
private static final String JDBC_CONNECTION = "jdbc:postgresql://localhost:5432/Employee_db";
|
176
|
+
|
177
|
+
/** ・ユーザー名 */
|
178
|
+
|
179
|
+
private static final String USER = "postgres";
|
180
|
+
|
181
|
+
/** ・パスワード */
|
182
|
+
|
183
|
+
private static final String PASS = "otikuyj";
|
184
|
+
|
185
|
+
/** ・タイムフォーマット */
|
186
|
+
|
187
|
+
private static final String TIME_FORMAT = "yyyy/MM/dd HH:mm:ss";
|
188
|
+
|
189
|
+
// 問② 入力されたIDを条件にログイン時間を更新するUPDATE文
|
190
|
+
|
191
|
+
/** ・SQL UPDATE文 */
|
192
|
+
|
193
|
+
private static final String SQL_UPDATE = "update employee_table set '?' = to_char(current_timestamp, 'yyyy/MM/dd HH24:MI:SS') where id = '?'";
|
194
|
+
|
195
|
+
// 問③ 入力されたIDとPassWordを条件と合致するデータを検索するSELECT文
|
196
|
+
|
197
|
+
/** ・SQL SELECT文 */
|
198
|
+
|
199
|
+
private static final String SQL_SELECT = "select * from employee_table where id = '?' AND password = '?'";
|
200
|
+
|
201
|
+
EmployeeBean employeeData = null;
|
202
|
+
|
203
|
+
// 送信されたIDとPassWordを元に社員情報を検索するためのメソッド
|
204
|
+
|
205
|
+
public EmployeeBean search(String id, String password) {
|
206
|
+
|
207
|
+
Connection connection = null;
|
208
|
+
|
209
|
+
Statement statement = null;
|
210
|
+
|
211
|
+
ResultSet resultSet = null;
|
212
|
+
|
213
|
+
PreparedStatement preparedStatement = null;
|
214
|
+
|
215
|
+
try {
|
216
|
+
|
217
|
+
// データベースに接続
|
218
|
+
|
219
|
+
Class.forName(POSTGRES_DRIVER);
|
220
|
+
|
221
|
+
connection = DriverManager.getConnection(JDBC_CONNECTION, USER, PASS);
|
222
|
+
|
223
|
+
statement = connection.createStatement();
|
224
|
+
|
225
|
+
// 処理が流れた時間をフォーマットに合わせて生成
|
226
|
+
|
227
|
+
Calendar cal = Calendar.getInstance();
|
228
|
+
|
229
|
+
SimpleDateFormat sdFormat = new SimpleDateFormat(TIME_FORMAT);
|
230
|
+
|
231
|
+
// PreparedStatementで使用するため、String型に変換
|
232
|
+
|
233
|
+
String login_time = sdFormat.format(cal.getTime());
|
234
|
+
|
235
|
+
/*
|
236
|
+
|
237
|
+
* 任意のユーザーのログインタイムを更新できるように、プリペアドステートメントを記述。
|
238
|
+
|
239
|
+
*/
|
240
|
+
|
241
|
+
// preparedStatementに実行したいSQLを格納
|
242
|
+
|
243
|
+
preparedStatement = connection.prepareStatement(SQL_UPDATE);
|
244
|
+
|
245
|
+
// 問④ preparedStatementを使って、第一引数に現在時刻を、第二引数にIDをセットしてください。
|
246
|
+
|
247
|
+
preparedStatement.setString(1, login_time);
|
248
|
+
|
249
|
+
preparedStatement.setString(2, id);
|
250
|
+
|
251
|
+
// 問⑤ UPDATEを実行する文を記述してください。
|
252
|
+
|
253
|
+
preparedStatement.executeUpdate(SQL);
|
254
|
+
|
255
|
+
/*
|
256
|
+
|
257
|
+
* UPDATEが成功したものを即座に表示
|
258
|
+
|
259
|
+
* 任意のユーザーを検索できるように、プリペアドステートメントを記述。
|
260
|
+
|
261
|
+
*/
|
262
|
+
|
263
|
+
preparedStatement = connection.prepareStatement(SQL_SELECT);
|
264
|
+
|
265
|
+
// 問⑥ preparedStatementを使って、第一引数にIDを、第二引数にPASSWORDをセットしてください。
|
266
|
+
|
267
|
+
preparedStatement.setString(1, id);
|
268
|
+
|
269
|
+
preparedStatement.setString(2, password);
|
270
|
+
|
271
|
+
// SQLを実行。実行した結果をresultSetに格納。
|
272
|
+
|
273
|
+
resultSet = preparedStatement.executeQuery();
|
274
|
+
|
275
|
+
while (resultSet.next()) {
|
276
|
+
|
277
|
+
// 問⑦ tmpName,tmpComment,tmpLoginTimeに適当なデータを格納してください。
|
278
|
+
|
279
|
+
String tmpName = resultSet.getString("name");
|
280
|
+
|
281
|
+
String tmpComment = resultSet.getString("comment");
|
282
|
+
|
283
|
+
String tmpLoginTime = resultSet.getString("login_time");
|
284
|
+
|
285
|
+
// 問⑧ EmployeeBeanに⑦で取得したデータを格納してください。
|
286
|
+
|
287
|
+
employeeData = new EmployeeBean();
|
288
|
+
|
289
|
+
employeeData.setName("tmpNam");
|
290
|
+
|
291
|
+
employeeData.setComment("tmpComment");
|
292
|
+
|
293
|
+
employeeData.setLogin_Time("tmpLoginTime");
|
294
|
+
|
295
|
+
}
|
296
|
+
|
297
|
+
// forName()で例外発生
|
298
|
+
|
299
|
+
} catch (ClassNotFoundException e) {
|
300
|
+
|
301
|
+
e.printStackTrace();
|
302
|
+
|
303
|
+
// getConnection()、createStatement()、executeQuery()で例外発生
|
304
|
+
|
305
|
+
} catch (SQLException e) {
|
306
|
+
|
307
|
+
e.printStackTrace();
|
308
|
+
|
309
|
+
} finally {
|
310
|
+
|
311
|
+
try {
|
312
|
+
|
313
|
+
if (resultSet != null) {
|
314
|
+
|
315
|
+
resultSet.close();
|
316
|
+
|
317
|
+
}
|
318
|
+
|
319
|
+
if (statement != null) {
|
320
|
+
|
321
|
+
statement.close();
|
322
|
+
|
323
|
+
}
|
324
|
+
|
325
|
+
if (connection != null) {
|
326
|
+
|
327
|
+
connection.close();
|
328
|
+
|
329
|
+
}
|
330
|
+
|
331
|
+
} catch (SQLException e) {
|
332
|
+
|
333
|
+
e.printStackTrace();
|
334
|
+
|
335
|
+
}
|
336
|
+
|
337
|
+
}
|
338
|
+
|
339
|
+
return employeeData;
|
340
|
+
|
341
|
+
}
|
342
|
+
|
343
|
+
}
|
344
|
+
|
345
|
+
```
|
1
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,421 +1,7 @@
|
|
1
|
-
|
1
|
+
解決しました!ありがとうございます!
|
2
|
+
|
3
|
+
大変助かりました。
|
2
4
|
|
3
5
|
|
4
6
|
|
5
|
-
EmployeeController①〜④
|
6
|
-
|
7
|
-
EmployeeService②〜⑧
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
SQLのカラム名は
|
12
|
-
|
13
|
-
|
7
|
+
※編集
|
14
|
-
|
15
|
-
・password
|
16
|
-
|
17
|
-
・name
|
18
|
-
|
19
|
-
・comment
|
20
|
-
|
21
|
-
・login_time
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
```EmploBean
|
26
|
-
|
27
|
-
public class EmployeeBean {
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
private String Id;
|
32
|
-
|
33
|
-
private String PassWord;
|
34
|
-
|
35
|
-
private String Name;
|
36
|
-
|
37
|
-
private String Comment;
|
38
|
-
|
39
|
-
private String Login_Time;
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
public void setId(String Id) {
|
44
|
-
|
45
|
-
this.Id = Id;
|
46
|
-
|
47
|
-
}
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
public String Id() {
|
52
|
-
|
53
|
-
return Id;
|
54
|
-
|
55
|
-
}
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
public void setPassWord(String PassWord) {
|
60
|
-
|
61
|
-
this.PassWord = PassWord;
|
62
|
-
|
63
|
-
}
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
public String getPassWord() {
|
68
|
-
|
69
|
-
return PassWord;
|
70
|
-
|
71
|
-
}
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
public void setName(String Name) {
|
76
|
-
|
77
|
-
this.Name = Name;
|
78
|
-
|
79
|
-
}
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
public String getName() {
|
84
|
-
|
85
|
-
return Name;
|
86
|
-
|
87
|
-
}
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
public void setLogin_Time(String Login_Time) {
|
92
|
-
|
93
|
-
this.Login_Time = Login_Time;
|
94
|
-
|
95
|
-
}
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
public String getLogin_Time() {
|
100
|
-
|
101
|
-
return Login_Time;
|
102
|
-
|
103
|
-
}
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
public void setComment(String Comment) {
|
108
|
-
|
109
|
-
this.Comment = Comment;
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
}
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
public String getComment() {
|
118
|
-
|
119
|
-
return Comment;
|
120
|
-
|
121
|
-
}
|
122
|
-
|
123
|
-
}
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
```
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
```EmployeeController
|
132
|
-
|
133
|
-
public class EmployeeController extends HttpServlet {
|
134
|
-
|
135
|
-
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
136
|
-
|
137
|
-
throws ServletException, IOException {
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
try {
|
142
|
-
|
143
|
-
// 問① index.htmlから送信されたIDとPassWordの値を取得できるように修正してください。
|
144
|
-
|
145
|
-
String id = request.getParameter("id");
|
146
|
-
|
147
|
-
String password = request.getParameter("pass");
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
/*
|
152
|
-
|
153
|
-
* IDとPassWordと元に、社員情報を検索する関数の呼び出し、結果をJSPに渡す処理
|
154
|
-
|
155
|
-
* ※ EmployeeBeanとEmployeeServiceをimportするのを忘れないでください。
|
156
|
-
|
157
|
-
*/
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
// 問② EmployeeServiceクラスをインスタンス化してください。
|
162
|
-
|
163
|
-
EmployeeService emps = new EmployeeService();
|
164
|
-
|
165
|
-
// 問③ EmployeeBeanに、EmployeeServiceよりsearch関数を呼び出し、返り値を格納してください。
|
166
|
-
|
167
|
-
emps.search("postgres", "otikuyj");
|
168
|
-
|
169
|
-
// 問④ [null]に適切な引数をセットしてください。
|
170
|
-
|
171
|
-
request.setAttribute("EmployeeBean", id);
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
} catch (Exception e) {
|
176
|
-
|
177
|
-
e.printStackTrace();
|
178
|
-
|
179
|
-
} finally {
|
180
|
-
|
181
|
-
ServletContext context = this.getServletContext();
|
182
|
-
|
183
|
-
RequestDispatcher dispatcher = context.getRequestDispatcher("/index.jsp");
|
184
|
-
|
185
|
-
dispatcher.forward(request, response);
|
186
|
-
|
187
|
-
}
|
188
|
-
|
189
|
-
}
|
190
|
-
|
191
|
-
}
|
192
|
-
|
193
|
-
```
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
```EmployeeService
|
198
|
-
|
199
|
-
public class EmployeeService {
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
// 問① 接続情報を記述してください
|
204
|
-
|
205
|
-
/** ドライバーのクラス名 */
|
206
|
-
|
207
|
-
private static final String POSTGRES_DRIVER = "org.postgresql.Driver";
|
208
|
-
|
209
|
-
/**
|
210
|
-
|
211
|
-
* ・JDMC接続先情報
|
212
|
-
|
213
|
-
* ポート番号(5432, 5433など)は個人で異なる可能性があります。
|
214
|
-
|
215
|
-
* 念の為、pgAdminにて対象のpostgreSQLバージョンよりメニューを開き、[プロパティ] -> [接続] を確認してください
|
216
|
-
|
217
|
-
*/
|
218
|
-
|
219
|
-
private static final String JDBC_CONNECTION = "jdbc:postgresql://localhost:5432/Employee_db";
|
220
|
-
|
221
|
-
/** ・ユーザー名 */
|
222
|
-
|
223
|
-
private static final String USER = "postgres";
|
224
|
-
|
225
|
-
/** ・パスワード */
|
226
|
-
|
227
|
-
private static final String PASS = "otikuyj";
|
228
|
-
|
229
|
-
/** ・タイムフォーマット */
|
230
|
-
|
231
|
-
private static final String TIME_FORMAT = "yyyy/MM/dd HH:mm:ss";
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
// 問② 入力されたIDを条件にログイン時間を更新するUPDATE文
|
236
|
-
|
237
|
-
/** ・SQL UPDATE文 */
|
238
|
-
|
239
|
-
private static final String SQL_UPDATE = "update employee_table set '?' = to_char(current_timestamp, 'yyyy/MM/dd HH24:MI:SS') where id = '?'";
|
240
|
-
|
241
|
-
// 問③ 入力されたIDとPassWordを条件と合致するデータを検索するSELECT文
|
242
|
-
|
243
|
-
/** ・SQL SELECT文 */
|
244
|
-
|
245
|
-
private static final String SQL_SELECT = "select * from employee_table where id = '?' AND password = '?'";
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
EmployeeBean employeeData = null;
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
// 送信されたIDとPassWordを元に社員情報を検索するためのメソッド
|
254
|
-
|
255
|
-
public EmployeeBean search(String id, String password) {
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
Connection connection = null;
|
260
|
-
|
261
|
-
Statement statement = null;
|
262
|
-
|
263
|
-
ResultSet resultSet = null;
|
264
|
-
|
265
|
-
PreparedStatement preparedStatement = null;
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
try {
|
270
|
-
|
271
|
-
// データベースに接続
|
272
|
-
|
273
|
-
Class.forName(POSTGRES_DRIVER);
|
274
|
-
|
275
|
-
connection = DriverManager.getConnection(JDBC_CONNECTION, USER, PASS);
|
276
|
-
|
277
|
-
statement = connection.createStatement();
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
// 処理が流れた時間をフォーマットに合わせて生成
|
282
|
-
|
283
|
-
Calendar cal = Calendar.getInstance();
|
284
|
-
|
285
|
-
SimpleDateFormat sdFormat = new SimpleDateFormat(TIME_FORMAT);
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
// PreparedStatementで使用するため、String型に変換
|
290
|
-
|
291
|
-
String login_time = sdFormat.format(cal.getTime());
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
/*
|
296
|
-
|
297
|
-
* 任意のユーザーのログインタイムを更新できるように、プリペアドステートメントを記述。
|
298
|
-
|
299
|
-
*/
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
// preparedStatementに実行したいSQLを格納
|
304
|
-
|
305
|
-
preparedStatement = connection.prepareStatement(SQL_UPDATE);
|
306
|
-
|
307
|
-
// 問④ preparedStatementを使って、第一引数に現在時刻を、第二引数にIDをセットしてください。
|
308
|
-
|
309
|
-
preparedStatement.setString(1, login_time);
|
310
|
-
|
311
|
-
preparedStatement.setString(2, id);
|
312
|
-
|
313
|
-
// 問⑤ UPDATEを実行する文を記述してください。
|
314
|
-
|
315
|
-
preparedStatement.executeUpdate(SQL);
|
316
|
-
|
317
|
-
/*
|
318
|
-
|
319
|
-
* UPDATEが成功したものを即座に表示
|
320
|
-
|
321
|
-
* 任意のユーザーを検索できるように、プリペアドステートメントを記述。
|
322
|
-
|
323
|
-
*/
|
324
|
-
|
325
|
-
preparedStatement = connection.prepareStatement(SQL_SELECT);
|
326
|
-
|
327
|
-
// 問⑥ preparedStatementを使って、第一引数にIDを、第二引数にPASSWORDをセットしてください。
|
328
|
-
|
329
|
-
preparedStatement.setString(1, id);
|
330
|
-
|
331
|
-
preparedStatement.setString(2, password);
|
332
|
-
|
333
|
-
// SQLを実行。実行した結果をresultSetに格納。
|
334
|
-
|
335
|
-
resultSet = preparedStatement.executeQuery();
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
while (resultSet.next()) {
|
340
|
-
|
341
|
-
// 問⑦ tmpName,tmpComment,tmpLoginTimeに適当なデータを格納してください。
|
342
|
-
|
343
|
-
String tmpName = resultSet.getString("name");
|
344
|
-
|
345
|
-
String tmpComment = resultSet.getString("comment");
|
346
|
-
|
347
|
-
String tmpLoginTime = resultSet.getString("login_time");
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
// 問⑧ EmployeeBeanに⑦で取得したデータを格納してください。
|
352
|
-
|
353
|
-
employeeData = new EmployeeBean();
|
354
|
-
|
355
|
-
employeeData.setName("tmpNam");
|
356
|
-
|
357
|
-
employeeData.setComment("tmpComment");
|
358
|
-
|
359
|
-
employeeData.setLogin_Time("tmpLoginTime");
|
360
|
-
|
361
|
-
}
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
// forName()で例外発生
|
366
|
-
|
367
|
-
} catch (ClassNotFoundException e) {
|
368
|
-
|
369
|
-
e.printStackTrace();
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
// getConnection()、createStatement()、executeQuery()で例外発生
|
374
|
-
|
375
|
-
} catch (SQLException e) {
|
376
|
-
|
377
|
-
e.printStackTrace();
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
} finally {
|
382
|
-
|
383
|
-
try {
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
if (resultSet != null) {
|
388
|
-
|
389
|
-
resultSet.close();
|
390
|
-
|
391
|
-
}
|
392
|
-
|
393
|
-
if (statement != null) {
|
394
|
-
|
395
|
-
statement.close();
|
396
|
-
|
397
|
-
}
|
398
|
-
|
399
|
-
if (connection != null) {
|
400
|
-
|
401
|
-
connection.close();
|
402
|
-
|
403
|
-
}
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
} catch (SQLException e) {
|
408
|
-
|
409
|
-
e.printStackTrace();
|
410
|
-
|
411
|
-
}
|
412
|
-
|
413
|
-
}
|
414
|
-
|
415
|
-
return employeeData;
|
416
|
-
|
417
|
-
}
|
418
|
-
|
419
|
-
}
|
420
|
-
|
421
|
-
```
|