상세 컨텐츠

본문 제목

odbc 연결 테스트~

Program/JAVA

by 마니씨 2010. 2. 1. 16:26

본문

import java.sql.*;

class  JDBC_Connect{
    public static void main(String[] args) {
        String driver = "oracle.jdbc.driver.OracleDriver";
        String url = "jdbc:oracle:thin:@xxx.xxx.xxx.xxx:1521:orcl";
    
        Connection con = null;
        Statement stmt = null;
    
        try{
            Class.forName(driver);
            con = DriverManager.getConnection(url, "scott", "tiger");
            stmt = con.createStatement();
            System.out.println("DB connect ok");
        }
        catch(Exception e){
            System.out.println("DB connect fail");
        }
        finally{
            try{
                if(stmt != null) stmt.close();
                if(con != null) con.close();
            }
            catch(Exception e){
                System.out.println(e.getMessage());
            }
        }
    }
}

C:\Program Files\Java\jdk1.6.0_18\jre\lib\ext 에 ojdbc14.jar 파일이 있어야지만 연결이 된다.


관련글 더보기