質問編集履歴
1
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -324,6 +324,88 @@
|
|
324
324
|
|
325
325
|
```
|
326
326
|
|
327
|
+
DepartmentDAO
|
328
|
+
|
329
|
+
```
|
330
|
+
|
331
|
+
import java.sql.Connection;
|
332
|
+
|
333
|
+
import java.sql.PreparedStatement;
|
334
|
+
|
335
|
+
import java.sql.ResultSet;
|
336
|
+
|
337
|
+
import java.sql.SQLException;
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
import jp.co.sss.crud.bean.Department;
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
public class DepartmentDAO {
|
346
|
+
|
347
|
+
/**
|
348
|
+
|
349
|
+
* 部署情報を部署IDで検索
|
350
|
+
|
351
|
+
*
|
352
|
+
|
353
|
+
* @param genreId
|
354
|
+
|
355
|
+
* 部署ID
|
356
|
+
|
357
|
+
* @return 部署情報
|
358
|
+
|
359
|
+
* @throws SQLException
|
360
|
+
|
361
|
+
* データベース操作失敗時に送出
|
362
|
+
|
363
|
+
*/
|
364
|
+
|
365
|
+
public static Department findByDepartment(int deptId) throws SQLException {
|
366
|
+
|
367
|
+
Department department = null;
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
Connection connection = DBManager.getConnection();
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM DEPARTMENT WHERE DEPT_ID = ?");
|
376
|
+
|
377
|
+
preparedStatement.setInt(1, deptId);
|
378
|
+
|
379
|
+
ResultSet resultSet = preparedStatement.executeQuery();
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
if (resultSet.next()) {
|
384
|
+
|
385
|
+
department = new Department();
|
386
|
+
|
387
|
+
department.setDeptId(resultSet.getInt("dept_id"));
|
388
|
+
|
389
|
+
department.setDeptName(resultSet.getString("dept_name"));
|
390
|
+
|
391
|
+
}
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
DBManager.close(preparedStatement, connection);
|
396
|
+
|
397
|
+
|
398
|
+
|
399
|
+
return department;
|
400
|
+
|
401
|
+
}
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
}
|
406
|
+
|
407
|
+
```
|
408
|
+
|
327
409
|
|
328
410
|
|
329
411
|
HTTPステータス500-というエラーが起き、説明に、The server encountered an internal error that prevented it from fulfilling this request.というのが表示されています。
|