Stack/JSP & Servlet
JSP로 JDBC프로그래밍 하기
Emmababy
2020. 11. 23. 21:41
728x90
* JDBC프로그래밍 절차 *
|
1. 드라이버로딩
Class.forName("oracle.jdbc.driver.OracleDriver"); |
2. DB 커넥션
DriverManager가 제공하는 getConnection()메서드 이용 |
* DriverManager.getConnection(String jdbcURL) * DriverManager.getConnection(String jdbcURL, String user, String password) |
* 특이사항 : DB와 연결된 커넥션 객체 리턴, Try-catch문 사용
3. 쿼리실행위한 Statement객체 구하기(쿼리실행가능)
Connection객체로 부터 Statement객체 생성 |
Statement stmt = conn.createStatement(); |
4. 쿼리실행시 사용가능 메서드 : executeQuery(ResultSet타입), executeUpdate(int타입)
5. 쿼리실행결과 사용
-ResultSet에 결과값 담아사용, ResultSet는 next()메서드 사용가능
rs = stmt.executeQuery("select * from member"); if(rs.next()){ String name = rs.getString("NAME"); // 행이 존재시 true를 리턴 } else { // 행이 존재하지않는경우 false를 리턴 } |
728x90