Data Source Explorer에 mysql 연결
Driver Class : com.mysql.cj.jdbc.Driver 로 설정해야함 주의.
그냥 해도 되지만 거쳐서 오는 것임.
프로젝트 별로 WEB-INF/lib에 커넥터J 자르파일 넣어줘서 DB설정 가능.
C:\workspace\jsp\tomcat\lib 여기에 넣으면 서버 공용으로 사용 가능.
항상 DB 사용 시 연결이 잘 되어있는지 확인해야한다.
// database와 연결하기 위한 필수 정보
// 현재 프로젝트 또는 서버에 jdbc 라이브러리가 정상적으로 등록되어 있는지 확인하기 위한 정보
String driver = "com.mysql.cj.jdbc.Driver";
// db server와 연결하기 위한 위치 정보
String url = "jdbc:mysql://localhost:3306/digital_jsp";
// 권한을 가진 사용자 계정 정보
String username = "digital";
String password = "12345";
Connection conn = null;
try{
Class.forName(driver);
out.println("Driver Class가 존재합니다.");
conn = DriverManager.getConnection(url,username,password);
out.println("DB 연결 완료");
out.println(conn);
}catch(ClassNotFoundException e){
out.println("Driver Class를 찾을 수 없습니다.");
}catch(SQLException e){
out.println("연결 요청 정보 오류 : "+ e.getMessage());
}finally{
if(conn != null){
conn.close();
}
}
'Java > JSP' 카테고리의 다른 글
7/11 서버에 커넥션 풀 등록, 페이징 처리 (7/10 실습 풀이), 모델 2(MVC) (0) | 2023.07.11 |
---|---|
07.10 connection pool (7.7 실습문제 풀이) (0) | 2023.07.10 |
07.06 JSP 실습문제 풀이, 에러페이지 , 간단한 양방향 암호화 (0) | 2023.07.06 |
7.04 dto,vo / useBean (0) | 2023.07.04 |
7.03 리스트를 이용한 회원가입 구현 (0) | 2023.07.03 |