ecsimsw
JDBC / 설치와 연결 / Connection 본문
JDBC
1. jdbc connector download
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();
}
}
에러 사항
'Database > SQL, JDBC' 카테고리의 다른 글
JDBC / sql 쿼리 적용 / Statement (0) | 2020.05.16 |
---|---|
JDBC / ClassNotFoundException / SQLException: The server time zone value (0) | 2020.05.15 |
mySql / JOIN / AS (0) | 2020.05.08 |
mySql / CRUD (0) | 2020.05.06 |
mySql / 데이터베이스, 테이블 생성과 삭제 (0) | 2020.05.06 |
Comments