231227 JAVA DepartmentsDAO
2023. 12. 27. 19:48ㆍ2023.11.21-2024.05.31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
package com.sukgi.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.sukgi.dto.DepartmentsDTO;
import conn.sukgi.db.DBConnection;
//데이터 접속 객체
public class DepartmentsDAO {
DBConnection dbConn = new DBConnection();
public List<DepartmentsDTO> selectDepartments() {
List<DepartmentsDTO> list = null;
Connection con = dbConn.getConn();
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "SELECT * FROM departments";
try {
pstmt = con.prepareStatement(sql);
rs = pstmt.executeQuery();
list = new ArrayList<DepartmentsDTO>();
while (rs.next()) {
DepartmentsDTO dto = new DepartmentsDTO();
dto.setDept_no(rs.getString("dept_no"));// 컬럼명
dto.setDept_name(rs.getString(2));// 컬럼위치 1부터 시작
list.add(dto);
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
}
|
cs |
'2023.11.21-2024.05.31' 카테고리의 다른 글
231227 HTML employees (0) | 2023.12.27 |
---|---|
231227 HTML index (0) | 2023.12.27 |
231227 JAVA DepartmentsDTO (0) | 2023.12.27 |
231227 JAVA Test-Employees (0) | 2023.12.27 |
231227 JAVA EmployeesDAO (0) | 2023.12.27 |