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
'기술 학습' 카테고리의 다른 글
| JDBC 코드(Gradle) (0) | 2025.03.31 |
|---|---|
| docker-compose.yml 설정 (0) | 2025.03.31 |
| Windows에서 Docker로 MySQL 실행하는 법 (0) | 2025.03.31 |
| Java 기본 개념 (1) | 2025.03.30 |
| 백엔드 java와 js 차이 (0) | 2025.03.27 |