728x90
package org.example;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectionTest {
public static void main(String[] args) {
Connection conn = null;
try {
conn =
DriverManager.getConnection(
"jdbc:mysql://127.0.0.1:3306/samplesdb?useUnicode=true&serverTimezone=Asia/Seoul",
"rootoj",
"1234");
if(conn != null) {
System.out.println("DBMS 연결 성공!!");
System.out.println(conn.getClass().getName());
}
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
} finally {
try {
if(conn != null) conn.close();
} catch (SQLException e) {
System.out.println("SQLException: " + e.getMessage());
}
}
}
}
728x90
'기타 기술 > Java' 카테고리의 다른 글
Java Spring Boot의 유용성에 대해 알아보자! 🚀 (0) | 2025.04.02 |
---|---|
게시판 만들기 백업 파일 (0) | 2025.04.01 |
Java 기본 개념 (1) | 2025.03.30 |