[JAVA] JDBC 순서 7단계

JDBC = Java DataBase Connectivity.
즉, 자바와 데이터베이스를 연결 시켜주는 것을 의미한다.
JDBC의 순서 (mySQL)
01단계 :드라이버 로딩(mysql 드라이버 로딩)
02단계 :Connection객체로 DB연결
03단계 :Query실행을 위한 준비
04단계 :Query실행
05단계 :Query실행결과 사용
06단계 :statement 또는 PreparedStatement객체 종료(close())
07단계 :DB연결(Connection 객체) 종료(close())
// 01단계 :드라이버 로딩(mysql 드라이버 로딩)
Class.forName("com.mysql.jdbc.Driver");
// 02단계 :Connection객체로 DB연결
// 1)ip 2)port번호 3)db접속id 4)db접속비번 5)db명(sid,service name)
String jdbcDriver = "db주소";
String dbUser = "db아이디";
String dbPass = "db비밀번호";
conn = DriverManager.getConnection(jdbcDriver, dbUser, dbPass);
// 03단계 :Query실행을 위한 준비
// ( statement 또는 PreparedStatement객체생성)
pstmt = conn.prepareStatement("SQL 코드");
pstmt.setString(1, u_id);
pstmt.setString(2, u_pw);
pstmt.setString(3, u_level);
pstmt.setString(4, u_name);
pstmt.setString(5, u_email);
pstmt.setString(6, u_phone);
pstmt.setString(7, u_addr);
// 04단계 :Query실행
int result = pstmt.executeUpdate();
//06단계 :statement 또는 PreparedStatement객체 종료(close())
// 07단계 :DB연결(Connection 객체) 종료(close())
ResultSet.close;
Statement.close;
Connection.close;