์นดํ…Œ๊ณ ๋ฆฌ ์—†์Œ

[Day 17 | MySQL ] ๋ทฐ, JDBC

๊น€์œ ๋‹ˆ์ฝ˜ 2021. 12. 1. 17:28

๋ทฐ:

๋ณ„๋„์˜ ์ฐฝ์ด๋‹ค.

๋ทฐ์˜ ์žฅ์ ์€ ๊ฐ„์†Œํ™”๋‹ค. 

์ปฌ๋Ÿผ๋ช… ์ผ์ผ์ด ๋‚˜์—ดํ•˜๋Š”๊ฑด ๋„ˆ๋ฌด ํž˜๋“ฌ, ๋ทฐ๋ฅผ ์ด์šฉํ•ด์„œ ์„ ํƒํ•œ ์ปฌ๋Ÿผ๋งŒ ๋ณด๊ฒŒํ•ด์ค„ ์ˆ˜ ์žˆ์Œ. 

 

 

๋ทฐ์˜ ํŠน์ง• -- p363

1. ์ฟผ๋ฆฌ๋ฅผ ๊ฐ„์†Œํ™”

2. ๋‹ค๋ฅธ ์‚ฌ๋žŒ์—๊ฒŒ ์ •ํ•ด์ง„ ๊ฒƒ๋งŒ ๋ณด์—ฌ์ค€๋‹ค(๋ณด์•ˆ์ ) 

3. ๋ทฐ๋Š” ์กฐํšŒ๋˜๋Š” ๊ฒƒ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ, ์ž…๋ ฅ, ์ˆ˜์ •, ์‚ญ์ œ ๋ชจ๋‘ ๊ฐ€๋Šฅํ•œ ๋ณ„๋„์˜ ์ฐฝ์ด๋‹ค. 

4. ๋ทฐ๋Š” ์‹ค์ฒด ๊ณต๊ฐ„์ด ์—†์–ด์„œ ํˆฌ์˜๋˜์–ด ์›๋ณธ ํ…Œ์ด๋ธ”์—์„œ ์ฒ˜๋ฆฌํ•˜๊ณ  ์˜จ๋‹ค. 

 

View01.sql 

-- View01.sql -- 

CREATE TABLE emp3
select * from emp; -- ํ…Œ์ด๋ธ” ๊ทธ๋Œ€๋กœ ์นดํ”ผ (์ปฌ๋Ÿผ ์‚ฌ์ด์ฆˆ,ํ…Œ์ด๋ธ”์€ ๋ณต์‚ฌ๋˜๋Š”๋ฐ ์ œ์•ฝ์กฐ๊ฑด, ์ธ๋ฑ์Šค ๋“ฑ์€ ๋ณต์‚ฌ์•ˆ )

SELECT * from emp3;


desc emp3; -- ์„ค์ •๋“ค์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Œ 

create view v1_emp3
as
SELECT empno, ename, job, hiredate, sal, comm, deptno from emp3;

select *  from v1_emp3; 


SELECT * from v1_emp3 ve 
where sal < 2000;

SELECT ve.ename , d.dname 
from v1_emp3 ve , dept d 
where (ve.deptno = d.deptno)
and (d.dname = 'sales');

-- emp 3์—์„œ ๊ธ‰์—ฌ๊ฐ€ 2000์ด์ƒ์ธ ์ง์›๋“ค์˜ ์‚ฌ๋ฒˆ, ์ด๋ฆ„, ๊ธ‰์—ฌ, ๋ถ€์„œ๋ฒˆํ˜ธ 
-- ์ด ๋ถ€๋ถ„์„ view๋กœ ์ƒ์„ฑํ•˜๊ธฐ

create view v2_emp3 
as
select e.empno , e.ename , e.sal , e.deptno from emp3 e 
WHERE e.sal > 2000; 

SELECT * from v2_emp3 ve ;

-- ๋ทฐ๋ฅผ ํ†ตํ•ด์„œ ์—…๋ฐ์ดํŠธ๋„ ๋ ๊นŒ์š”? 

-- v2_emp3 ์—์„œ ์‚ฌ๋ฒˆ์ด 7566์ธ ์ง์›์˜ ๋ถ€์„œ๋ฒˆํ˜ธ๋ฅผ 30์œผ๋กœ ์ˆ˜์ •ํ•ด๋ณด์„ธ์š”.

update v2_emp3 
set deptno = 30
where empno = 7566;

SELECT deptno 
from v2_emp3 ve
where empno = 7566;

SELECT deptno
from emp3
where empno = 7566;

-- view ์—์„œ ๋ณ€๊ฒฝ์‚ฌํ•ญ์ด ์žˆ์œผ๋ฉด ์›๋ณธ์—์„œ๋„ ๋˜‘๊ฐ™์€ ๋ณ€ํ™”๊ฐ€ ์ผ์–ด๋‚จ 

delete from v2_emp3 
where empno = 7566;

-- v2_emp3์—์„œ ์ง์›(7777, Tom, 4000, 20) ์ž…๋ ฅ 

insert into v2_emp3 values(7777, 'Tom', 4000, 20);

DELETE from v2_emp3 
WHERE empno = 7777;

-- v2_emp3์—์„œ ์ง์›(7788, Jane, 1000, 20) ์ž…๋ ฅ 
-- (view์—์„œ sal2000์ด์ƒ์œผ๋กœ ๋งŒ๋“ค์—ˆ๊ธฐ ๋•Œ๋ฌธ์— view ์•„๋‹Œ ์›๋ณธ์—๋งŒ ๋“ค์–ด๊ฐ )

INSERT into v2_emp3 values (7788, 'Jane', 1000, 20);

DELETE from emp3 
where ename = 'Jane';

SELECT * from v2_emp3 ve ;

SELECT * from emp3 e ;

-- ์ถ”๊ฐ€๋Š” ๋ฒ”์œ„ ๋ฐ–์—์„œ๋„ ๋˜๋Š”๋ฐ ์‚ญ์ œ/๋ณ€๊ฒฝ์€ ๋˜์ง€ ์•Š๋Š”๋‹ค. 
DELETE from v2_emp3 where (sal = 1000);
UPDATE v2_emp3 set deptno = 40 where (sal = 1000);




-- View ๋ณ€๊ฒฝcreate view v1_emp3
alter view v2_emp3
as
	SELECT empno, ename, job, hiredate, sal, comm, deptno 
	from emp3
	where (sal >= 2000) 
with check option;


INSERT into v2_emp3 values (9999, 'Alice', 999, 20);

create view v3_emp3
as 
select ename, empno, ((12*sal) + ifnull(null, 0 )) "์—ฐ์†Œ๋“" 
from emp3;

DROP view v3_emp ; -- ๋ทฐ์‚ญ์ œ




create view v4_emp
as
select  ee.ename '์ง์›', ee.job, ed.dname '์ง์›๋ถ€์„œ', ee.sal, 
		es.grade , me.ename '์ƒ๊ด€', md.dname '์ƒ๊ด€๋ถ€์„œ'
from emp ee, dept ed, salgrade es , emp me, dept md
where (ee.deptno = ed.deptno)
 and  (ee.sal between es.losal and es.hisal)
 and  (ee.mgr = me.empno)
 and  (me.deptno = md.deptno)
 and  (ee.sal < ( select avg(sal)
					from emp
					where (job = ( select job
									from emp 
									where (ename = 'Martin')))));

 

 


 

 

Web Server ๊ตฌ์„ฑ - JDBC

์›น ๊ด€๋ จ ํ”„๋กœ์ ํŠธ์—๋Š”

1. UI

2. Front end 

3. Back end 

4. Database 

5. VM

ํด๋ผ์ด์–ธํŠธ ์ชฝ์— ๊ฐ€๊นŒ์šด -- html (html์—๋„ ๊ธ€์ž์ฒด, ์ƒ‰ ์ •ํ•˜๋Š” ๊ฒƒ css), ์„ฑ๋Šฅ, ๊ธฐ๋Šฅ์„ ๋Œ๋ฆด ์ˆ˜ ์žˆ๋Š”๊ฑฐ java script, jquery, 

ui ์Šคํ† ๋ฆฌ๋ณด๋“œ 

๋ฐฑ์—”๋“œ : jsp(ํ™”๋ฉด ๋‹จ view) / servlet(๋‚ด๋ถ€์— java๊ฐ€ ๋Ž, control) / ๋ฐ์ดํ„ฐ ๋ฒ ์ด์Šค์— ์—ฐ๊ฒฐ์‹œํ‚ค๋Š” ๊ฒƒ, db class (๋ชจ๋ธ) 

             --> MVC ํŒจํ„ด (์ด ํŒจํ„ด์— ๋Œ€ํ•ด ํ”„๋ ˆ์ž„์›Œํฌ ์ œ๊ณตํ•˜๋Š” ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ spring์ด๋ผ๊ณ  ํ•จ --> ์ข€ ๋” ๋น ๋ฅด๊ฒŒ --> ์Šคํ”„๋ง ๋ถ€ํŠธ)

 

VM์€ ๋Ž์˜ต์Šค๋กœ ๊ฐ€๋Š” ๊ฒƒ. ๋„์ปค(๋„คํŠธ์›Œํฌ), ์ฝ”๋ณด๋…ธ์ธ (๊ฐ€์ƒํ™”์— ๋Œ€ํ•œ ์ด์•ผ๊ธฐ) ๋ผ๊ณ  ํ•˜๋Š” ๊ฒƒ๋“ค์ด ํŒŒ์ƒ๋˜์–ด์„œ ๋‚˜์˜ด. 

 

์Šคํ”„๋ง๋ถ€ํŠธ๋„ VM๊ณผ ๋งž๋‹ฟ๋Š” ๊ฒƒ -- Spring Cloud

์—ฌ๋Ÿฌ๊ฐ€์ง€ ๊ฐ€์ƒํ™”๊ฐ€ ์žˆ๋Š”๋ฐ DevOps์—์„œ ๋งํ•˜๋Š” ๊ฐ€์ƒํ™”๋Š” ํ”„๋กœ์„ธ์Šค ๊ฐ€์ƒํ™”(OS ๊ฐ€์ƒํ™” ์•„๋‹˜) 

 

DB์—์„œ ์šฐ๋ฆฌ๋Š” RDB๋ผ๋Š” ๊ฒƒ์„ ๋ฐฐ์› ๋‹ค. 

RDB๋ผ๊ณ  ํ•˜๋Š” ๊ฒƒ์—, ํ…Œ์ด๋ธ” ERD ๋ผ๋Š” ๊ฒƒ์„ ํ•จ. (Entity, Attribute, Relationship)

 

๋ฐ์ดํ„ฐ ์กฐํšŒ ( SubQuery, Join, where, group by having)

DML ( insert, update, delete) ๊ทธ ๋‹ค์Œ์— ์—”ํ‹ฐํ‹ฐ๋ฅผ ๊ตฌ์„ฑํ•˜๋ ค๋ฉด, ERD ์„ค๊ณ„ ํ›„ DML ๋งž๋‹ฟ๋Š” ๊ณณ์—์„œ

DDL ( Table(Datatype, size, constraint) ์ด ๋ฐœ์ƒ. ์ด๋•Œ (create, alter, drop)์„ ํ•จ. 

 

์ด๋ ‡๊ฒŒ ์ œ์ž‘์„ ํ•œ ๊ฒƒ์„ ์ž๋ฐ”์—์„œ ๋Œ์–ด์˜ค๋ ค๋ฉด ๋ชจํ˜•์„ ๋งŒ๋“ค์–ด์•ผ. 

์ด์ œ ์ด ๋ชจํ˜•์„ ๋งŒ๋“ค์–ด๋ณด์ž. 

์—ฐ๊ฒฐ๊ณ ๋ฆฌ๊ฐ€ ํ•„์š”ํ• ํ…๋ฐ? ๊ทธ ์—ฐ๊ฒฐ๊ณ ๋ฆฌ๊ฐ€ JDBC๋ผ๋Š” ์—ฐ๊ฒฐ๊ณ ๋ฆฌ!

 

์ž๋ฐ”์ชฝ์—์„œ mysql์„ ์—ฐ๊ฒฐํ•˜๋Š” JDBC๊ฐ€ ํ•„์š”ํ•˜๊ตฌ๋‚˜.

JDBC MySQL ์—ฐ๋™ํ•˜๊ธฐ

https://m.blog.naver.com/pjok1122/221727915740

 

JDBC MySQL ์—ฐ๋™ํ•˜๊ธฐ (2)

1. JDBC์˜ ์‹คํ–‰์ˆœ์„œ 1) DB Driver๋ฅผ Java ๋ฉ”๋ชจ๋ฆฌ ์ƒ์œผ๋กœ ๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค. 2) Driver๋ฅผ ํ†ตํ•ด Java์™€ ...

blog.naver.com

๋งฅ์€ ์ด๊ฑฐ ์ฐธ๊ณ : https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=suda552&logNo=220725289307 

 

JDBC๋ฅผ ์ด์šฉํ•˜์—ฌ Mysql ์—ฐ๋™ํ•˜๊ธฐ (MAC)

์ด ํฌ์ŠคํŒ…์€ http://doit2day.tistory.com/37 ๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ์ž‘์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค MySql์ด ๊น”๋ ค์žˆ๋Š” ์ƒํƒœ์—์„œ JD...

blog.naver.com

 

 

 

์™€ ์ด๊ฑฐ ์•ˆ๋˜์–ด์„œ ํ•œ์ฐธ ๊ณ ์ƒํ–ˆ๋‹ค.....

 

 

 


์ดํ•˜ ์ดํด๋ฆฝ์Šค์—์„œ ์ž‘์„ฑ 

 

MyConn01.java

import java.sql.*;
import java.util.*;

public class MyConn01 {

	public static void main(String[] args) {	
		// JDBC ๋“œ๋ผ์ด๋ธŒ ๋กœ๋“œ (์—ฐ๊ฒฐ) 
		// Database Connection ์—ฐ๊ฒฐ 
		// statement ์ƒ์„ฑ(์‚ฌ๋‹ค๋ฆฌ์ฐจ ํŒ๋„ฌ)
		// SQL ์ „์†ก  --> executeQuery(), executeUpdate()
		// Result set(๊ฒฐ๊ณผ) ๋ฐ›๊ธฐ
		// Database connection ํ•ด์ œ
	
		
		/////////////////////////////////////////////////

		
		// JDBC ๋“œ๋ผ์ด๋ธŒ ๋กœ๋“œ (์—ฐ๊ฒฐ) 
		String jdbcDriver = "com.mysql.cj.jdbc.Driver";
		String jdbcUrl = "jdbc:mysql://localhost/empdb";
		
		try {
		Class.forName(jdbcDriver);
		// Database Connection ์—ฐ๊ฒฐ
		
		Connection conn = DriverManager.getConnection(jdbcUrl,"root","1234");
		// Statement ์ƒ์„ฑ
		String sql = "select * from dept";
		Statement stmt = conn.createStatement();
		
		// SQL ์ „์†ก --> executeQuery(), executeUpdate()
		// ResultSet(๊ฒฐ๊ณผ) ๋ฐ›๊ธฐ
		ResultSet rs = stmt.executeQuery(sql);
		
		while(rs.next()) {
			System.out.printf("%d | %-10s | %-10s \n",rs.getInt("deptno"),rs.getString(2),rs.getString("loc"));
		}
	
		
		
		// Database Connection ํ•ด์ œ
		stmt.close();
		conn.close();
		}
		catch (Exception e) {
			System.out.println("์—ฐ๊ฒฐ ์•ˆ๋จ");
		}
	}

}

 

 

 

MyConn02.java

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class MyConn02 {

	public static void main(String[] args) {
		
		Connection conn = null;
		
		String jdbcDriver = "com.mysql.cj.jdbc.Driver";
		String jdbcUrl = "jdbc:mysql://localhost:3306/empdb?serverTimezone=UTC";
		String dbUser  = "root";
		String dbPwd   = "1234";
		
		String sqlSelect = "select * from dept10";
		PreparedStatement pstmt = null;
		ResultSet rs = null; 
		
		int iDeptno = 0; String sDname = null; String sLoc = null;
		
		Scanner sc = new Scanner(System.in);
		
		System.out.println("๋ถ€์„œ ๋ฒˆํ˜ธ ์ž…๋ ฅ => "); iDeptno = sc.nextInt(); 
		
		System.out.println("๋ถ€์„œ ์ด๋ฆ„ ์ž…๋ ฅ => "); sDname = sc.next();
		
		System.out.println("๋ถ€์„œ ์œ„์น˜ ์ž…๋ ฅ => "); sLoc = sc.next();
		
		String sqlInsert = "insert into dept10 values(?,?,?)"; 
				
		try {
			// 1. JDBC ๋“œ๋ผ์ด๋ธŒ ๋กœ๋“œ (์—ฐ๊ฒฐ) 
			Class.forName(jdbcDriver);
			// 2. Database Connection ์—ฐ๊ฒฐ
			conn = DriverManager.getConnection(jdbcUrl,dbUser,dbPwd );
			
			System.out.println("Connection ์—ฐ๊ฒฐ");
			// 3. statement ์ƒ์„ฑ 
			pstmt = conn.prepareStatement(sqlInsert);
			// 4. SQL ์ „์†ก --> executeQuery(), executeUpdate()
						
			pstmt.setInt(1, iDeptno); 
			pstmt.setString(2, sDname);
			pstmt.setString(3, sLoc);
			
			int resultCount = pstmt.executeUpdate();
			// 5. ResultSet(๊ฒฐ๊ณผ) ๋ฐ›๊ธฐ ‚
			rs = pstmt.executeQuery(sqlSelect);
			
			if(resultCount > 0 ) {System.out.println("์ •์ƒ ์ž…๋ ฅ"); }
			else {System.out.println("์ž…๋ ฅ ์•ˆ๋จ "); }
				
			while(rs.next()) {
				System.out.printf("%d | %-10s | %-10s %n",rs.getInt("deptno"),rs.getString(2),rs.getString("loc"));
			}	
			
			// 6. Database Connection ํ•ด์ œ 
			System.out.println("Connection ํ•ด์ œ");
			pstmt.close();
			conn.close();
		}
		catch(SQLException e) {
			System.out.printf("Exception: \r\n %s", e);
			System.out.println("๋กœ๋“œ ์‹คํŒจ ");
		}
		catch(ClassNotFoundException e) {
			System.out.printf("Exception: \r\n %s", e);
			System.out.println("Driver ์—ฐ๊ฒฐ ์•ˆ๋จ");
		}
	}

}

 

 

MyConn03.sql (Update)

- ๋ถ€์„œ ๋ฒˆํ˜ธ๋กœ ๋ถ€์„œ ์œ„์น˜๋ฅผ ๋ณ€๊ฒฝ 

IT --> Jeju

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

public class MyConn03 {

	public static void main(String[] args) {

		Connection conn = null;
		
		String jdbcDriver = "com.mysql.cj.jdbc.Driver";
		String jdbcUrl = "jdbc:mysql://localhost:3306/empdb?serverTimezone=UTC";
		String dbUser  = "root";
		String dbPwd   = "1234";
		
		String sqlSelect = "select * from dept10";
		PreparedStatement pstmt = null;
		ResultSet rs = null; 
		
		int iDeptno = 0; String sDname = null; String sLoc = null;
		Scanner sc = new Scanner(System.in);
		
		System.out.println("๋ถ€์„œ ๋ฒˆํ˜ธ ์ž…๋ ฅ => "); iDeptno = sc.nextInt();
		System.out.println("๋ณ€๊ฒฝ ์ง€์—ญ ์ž…๋ ฅ => "); sLoc = sc.next();
		String sqlUpdate = "update dept10 set loc = ? where deptno = ?;";
		try {
		// 1. JDBC ๋“œ๋ผ์ด๋ธŒ ๋กœ๋“œ (์—ฐ๊ฒฐ) 
		Class.forName(jdbcDriver);
		
		// 2. Database Connection ์—ฐ๊ฒฐ 
		conn = DriverManager.getConnection(jdbcUrl, dbUser, dbPwd);
		
		System.out.println("Connection ์—ฐ๊ฒฐ ");
		
		// statement ์ƒ์„ฑ(์‚ฌ๋‹ค๋ฆฌ์ฐจ ํŒ๋„ฌ)
		pstmt = conn.prepareStatement(sqlUpdate);
		
		// SQL ์ „์†ก  --> executeQuery(), executeUpdate()
		pstmt.setInt(2, iDeptno); 
		pstmt.setString(1, sLoc); 
		
		int resultCount = pstmt.executeUpdate();
		// 5. ResultSet(๊ฒฐ๊ณผ) ๋ฐ›๊ธฐ ‚
		rs = pstmt.executeQuery(sqlSelect);
		
		if(resultCount > 0 ) {System.out.println("์ •์ƒ ์ž…๋ ฅ"); }
		else {System.out.println("์ž…๋ ฅ ์•ˆ๋จ "); }
			
		while(rs.next()) {
			System.out.printf("%d | %-10s | %-10s %n",rs.getInt("deptno"),rs.getString(2),rs.getString("loc"));
		}	
		// 6. Database Connection ํ•ด์ œ 
		System.out.println("Connection ํ•ด์ œ");
		pstmt.close();
		conn.close();
	}
	catch(SQLException e) {
		System.out.printf("Exception: \r\n %s", e);
		System.out.println("์—ฐ๊ฒฐ ์•ˆ๋จ");
	}
	catch(ClassNotFoundException e) {
		System.out.printf("Exception: \r\n %s", e);
		System.out.println("Driver ๋กœ๋“œ ์‹คํŒจ");
	}

}
}

 

MyConn04.sql (Delete)

- ๋ถ€์„œ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅ

- ํ•ด๋‹น ๋ถ€์„œ๊ฐ€ ์ œ๊ฑฐ 

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

public class MyConn04 {

	public static void main(String[] args) {
		
		Connection conn = null;
		
		
		String jdbcDriver = "com.mysql.cj.jdbc.Driver";
		String jdbcUrl = "jdbc:mysql://localhost:3306/empdb?serverTimezone=UTC";
		String dbUser  = "root";
		String dbPwd   = "1234";
		
		String sqlSelect = "select * from dept10";
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		
		int iDeptno = 0;  String sLoc = null;
		Scanner sc = new Scanner(System.in);
		
		System.out.println("๋ถ€์„œ ๋ฒˆํ˜ธ ์ž…๋ ฅ => "); iDeptno = sc.nextInt();
		String sqlDelete = "delete from dept10 where deptno = ?;";
		
		try {
		// 1. JDBC ๋“œ๋ผ์ด๋ธŒ ๋กœ๋“œ (์—ฐ๊ฒฐ) 
		Class.forName(jdbcDriver);

		
		// 2. Database Connection ์—ฐ๊ฒฐ 	
		conn = DriverManager.getConnection(jdbcUrl, dbUser, dbPwd);
		
		System.out.println("Connection ์—ฐ๊ฒฐ ");
		
		// 3. statement ์ƒ์„ฑ(์‚ฌ๋‹ค๋ฆฌ์ฐจ ํŒ๋„ฌ)
		pstmt = conn.prepareStatement(sqlDelete);

		
		// 4. SQL ์ „์†ก  --> executeQuery(), executeUpdate()
		pstmt.setInt(1, iDeptno);
		
		
		int resultCount = pstmt.executeUpdate();

		// 5. Result set(๊ฒฐ๊ณผ) ๋ฐ›๊ธฐ
		rs = pstmt.executeQuery(sqlSelect);
		
		
		if(resultCount > 0 ) {System.out.println("์ •์ƒ ์ž…๋ ฅ");}
		else {System.out.println("์ž…๋ ฅ ์•ˆ๋จ "); }
		
		
		while(rs.next()) {
			System.out.printf("%d | %-10s | %-10s %n",rs.getInt("deptno"),rs.getString(2),rs.getString("loc"));
		}	
		

		// 6. Database connection ํ•ด์ œ
		System.out.println("Connection ํ•ด์ œ");
		pstmt.close();
		conn.close();
	}
	catch(SQLException e) {
		System.out.printf("Exception: \r\n %s", e);
		System.out.println("์—ฐ๊ฒฐ ์•ˆ๋จ");
	}
	catch(ClassNotFoundException e) {
		System.out.printf("Exception: \r\n %s", e);
		System.out.println("Driver ๋กœ๋“œ ์‹คํŒจ");
	}
		

}
}

DAO, DTO, VO ๊ฐ€ ๋ฌด์—‡์ธ์ง€ ์กฐ์‚ฌํ•ด์„œ ์ œ์ถœ :