|
@@ -5,6 +5,7 @@ import java.sql.DriverManager;
|
5
|
5
|
import java.sql.ResultSet;
|
6
|
6
|
import java.sql.SQLException;
|
7
|
7
|
import java.sql.Statement;
|
|
8
|
+import java.util.ArrayList;
|
8
|
9
|
import java.util.List;
|
9
|
10
|
|
10
|
11
|
/**
|
|
@@ -96,6 +97,41 @@ public class DatabaseUtil {
|
96
|
97
|
return result;
|
97
|
98
|
|
98
|
99
|
}
|
|
100
|
+
|
|
101
|
+ // 전체조회
|
|
102
|
+ public List<Employee> dbSelect() {
|
|
103
|
+ String sql = "select * from employees";
|
|
104
|
+ return query(sql);
|
|
105
|
+ }
|
|
106
|
+ // 선택조회
|
|
107
|
+ public List<Employee> dbSelect(String name) {
|
|
108
|
+ String sql = "select * from employees where name like %'" + name + "'%";
|
|
109
|
+ return query(sql);
|
|
110
|
+ }
|
|
111
|
+
|
|
112
|
+ private List<Employee> query(String query) {
|
|
113
|
+ List<Employee> em = new ArrayList<Employee>();
|
|
114
|
+ try {
|
|
115
|
+ Statement statement = connection.createStatement();
|
|
116
|
+ ResultSet rs = statement.executeQuery(query);
|
|
117
|
+
|
|
118
|
+ while(rs.next()){
|
|
119
|
+ int employee_id = rs.getInt("employee_id");
|
|
120
|
+ String name = rs.getString("name");
|
|
121
|
+ double hourly_pay = rs.getDouble("hourly_pay");
|
|
122
|
+ long employee_contact = rs.getLong("employee_contact");
|
|
123
|
+
|
|
124
|
+ Employee e1 = new Employee(employee_id, name, hourly_pay, employee_contact);
|
|
125
|
+ em.add(e1);
|
|
126
|
+ }
|
|
127
|
+ rs.close();
|
|
128
|
+ } catch (SQLException e) {
|
|
129
|
+ // TODO Auto-generated catch block
|
|
130
|
+ e.printStackTrace();
|
|
131
|
+
|
|
132
|
+ }
|
|
133
|
+ return em;
|
|
134
|
+ }
|
99
|
135
|
|
100
|
136
|
|
101
|
137
|
|