tobby48 5 years ago
parent
commit
00d6dc4aee

+ 36
- 0
src/kr/co/swh/lecture/database/java/DatabaseUtil.java View File

@@ -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
 

+ 41
- 0
src/kr/co/swh/lecture/database/java/Employee.java View File

@@ -0,0 +1,41 @@
1
+package kr.co.swh.lecture.database.java;
2
+
3
+public class Employee {
4
+	private int employee_id;
5
+	private String name;
6
+	private double hourly_pay;
7
+	private long employee_contact;
8
+	
9
+	public Employee(int employee_id, String name, double hourly_pay, long employee_contact) {
10
+		this.employee_id = employee_id;
11
+		this.name = name;
12
+		this.hourly_pay = hourly_pay;
13
+		this.employee_contact = employee_contact;
14
+	}
15
+	
16
+	public int getEmployee_id() {
17
+		return employee_id;
18
+	}
19
+	public void setEmployee_id(int employee_id) {
20
+		this.employee_id = employee_id;
21
+	}
22
+	public String getName() {
23
+		return name;
24
+	}
25
+	public void setName(String name) {
26
+		this.name = name;
27
+	}
28
+	public double getHourly_pay() {
29
+		return hourly_pay;
30
+	}
31
+	public void setHourly_pay(double hourly_pay) {
32
+		this.hourly_pay = hourly_pay;
33
+	}
34
+	public long getEmployee_contact() {
35
+		return employee_contact;
36
+	}
37
+	public void setEmployee_contact(long employee_contact) {
38
+		this.employee_contact = employee_contact;
39
+	}
40
+	
41
+}

+ 13
- 3
src/kr/co/swh/lecture/database/java/Wheather.java View File

@@ -1,5 +1,7 @@
1 1
 package kr.co.swh.lecture.database.java;
2 2
 
3
+import java.util.List;
4
+
3 5
 public class Wheather {
4 6
 
5 7
 	public static void main(String[] args) {
@@ -16,9 +18,17 @@ public class Wheather {
16 18
 		
17 19
 		
18 20
 		DatabaseUtil u = new DatabaseUtil(dbUrl, dbName, user, password);
19
-		u.DB_URL
20
-		u.dbInsert(stores)
21
-		u.close();
21
+//		u.dbInsert(stores)
22
+		List<Employee> l = u.dbSelect("차");
23
+		for(Employee e : l) {
24
+			spsp
25
+			
26
+			sdfsd
27
+			sdf
28
+			df
29
+			d
30
+			d
31
+		}
22 32
 		
23 33
 		
24 34