ecsimsw

JDBC / 설치와 연결 / Connection 본문

JDBC / 설치와 연결 / Connection

JinHwan Kim 2020. 5. 15. 20:02

JDBC

 

  1. jdbc connector download

 

MySQL :: Download Connector/J

MySQL Connector/J 8.0 is highly recommended for use with MySQL Server 8.0, 5.7 and 5.6. Please upgrade to MySQL Connector/J 8.0.

dev.mysql.com

  2. build path 설정

 

프로젝트 우클릭 -> properties -> java build path -> libraries -> Add External JARs -> connector jars 지정

 

 

연결 확인

 

  1. import java.sql.*;

   

  2. Class.forName("com.mysql.jdbc.Driver");

 

  3.  Connection conn = DriverManager.getConnection(url, id, pw);

 

  // url = "jdbc:mysql://localhost:'port'/'dbName';  

Connection conn = null;

try{
    Class.forName("com.mysql.jdbc.Driver");
    String url ="jdbc:mysql://localhost:3306/dbName";
    conn = DriverManager.getConnection(url, "id", "pw");
    System.out.println("연결 성공");

}
catch(ClassNotFoundException e){
    System.out.println(e+"드라이버 로딩 실패");
}
catch(SQLException e){
    System.out.println("에러: " + e);
}
finally{
    try{
        if( conn != null && !conn.isClosed()){
            conn.close();
        }
    }
    catch( SQLException e){
        e.printStackTrace();
    }
}

 

 

 

에러 사항

 

 

JDBC / ClassNotFoundException / SQLException: The server time zone value

JDBC 설치 및 연결 JDBC 설치와 연결 JDBC 1. jdbc connector download MySQL :: Download Connector/J MySQL Connector/J 8.0 is highly recommended for use with MySQL Server 8.0, 5.7 and 5.6. Please upgrad..

ecsimsw.tistory.com

 

Comments