Computer Science/DB시스템및프로그래밍
JDBC를 이용한 Oracle 컨넥션 설정
Theo Kim
2011. 3. 9. 10:40
import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class JDBCDemo { public static void main(String[] args) { Connection conn = null; // 컨넥션 연결을 위한 try { Class.forName("oracle.jdbc.driver.OracleDriver"); System.out.println("드라이버 로딩 성공"); conn = DriverManager.getConnection("jdbc:oracle:thin:@IP_주소:1521:ORCL", "계정_이름", "계정_비밀번호"); // 컨넥션 설정 System.out.println("데이터베이스 연결 성공"); } catch(ClassNotFoundException cnfe) { System.out.println("드라이버 로딩 실패"); cnfe.printStackTrace(); } catch(SQLException se) { System.out.println("데이터베이스 연결 실패"); se.printStackTrace(); } finally { try { if(conn != null) { conn.close(); System.out.println("데이터베이스 연결 해제 성공"); } } catch(SQLException se) { System.out.println("데이터베이스 연결 해제 실패"); se.printStackTrace(); } } } }