NY's 개발일기
[PostgreSQL] JDBC를 활용하여 Java와 PostgreSQL 연동하기 본문
※ Java 실행의 경우 IntelliJ IDEA를 사용하였습니다.
1. PostgreSQL JDBC Download
https://jdbc.postgresql.org/download.html
PostgreSQL JDBC Download
Download About Binary JAR file downloads of the JDBC driver are available here and the current version with Maven Repository. Because Java is platform neutral, it is a simple process of just downloading the appropriate JAR file and dropping it into your cl
jdbc.postgresql.org
해당 페이지에 접속하여 PostgreSQL JDBC Driver를 다운받습니다.
2. Project 생성 후, 다운 받은 파일을 Libraries 에 추가
(1) Project Structure 클릭
(2) 다운 받은 파일을 Libraries 에 추가
(3) OK 클릭
3. 다음 코드를 실행
import java.sql.*;
public class Main {
public static void main(String[] args) throws SQLException {
String url = "jdbc:postgresql://localhost/";
String user = "postgres";
String password = "*****"; //password 입력
try
{
Connection connect = null;
connect = DriverManager.getConnection(url, user, password);
if(connect != null) {
System.out.println("Connection successful!!");
}
else {
throw new SQLException("no connection...");
}
} catch (SQLException ex) {
throw ex;
}
}
}
password 를 넣고 실행하면 "Connection successful" 출력문을 확인할 수 있습니다.
'Study > Database' 카테고리의 다른 글
[Redis] Redis-cli 기본 명령어 정리 (0) | 2022.01.06 |
---|---|
[Redis] Docker를 통해 Redis 설치하기 (0) | 2022.01.04 |
[Redis] Redis 릴리즈를 다운로드하여 설치하기 (for Windows) (0) | 2022.01.03 |
[PostgreSQL] JDBC를 이용하여 Create문, Insert문 처리하기 (0) | 2021.04.19 |