1. DBMS에 맞는 드라이버 데이터를 로드
Class.forName("oracle.jdbc.driver.OracleDriver");
//Class.forName()메서드를 통하여 Oracle에서 제공하는 Driver 클래스를 JVM method area에 로딩한다.
2. DB에 연결(Connection을 확보한다.)
final String url = "jdbc:oracle:thin:@localhost:1521:xe";
final String user ="seo";
final String pw = "1234";
Connection conn = DriverManager.getConnection(url, user, pw);
//데이터 베이스를 연결한다.
//getConnection()메서드를 통해 Connection객체를 반환하고,
//이 객체를 통해 쿼리를 다룰 수 있는 statement를 작성할 수 있다.
3. 데이터를 read, write
Statement stmt = con.createStatement();
String sql = "select * from student";
ResultSet result = stmt.executeQuery(sql);
4. DB와의 연결을 해제
stmt.close();
conn.close();
'JAVA' 카테고리의 다른 글
day20) 트랜잭션1 (0) | 2022.01.23 |
---|---|
day19) JDBC를 이용한 DB연동2 - CRUD구현 (0) | 2022.01.22 |
day17) [용어 정리 ] 컴포넌트, DBMS, JDBC (0) | 2022.01.19 |
day15) MVC패턴 기본구조 (0) | 2022.01.14 |
day14) 파일 입출력 (0) | 2022.01.14 |
댓글