Computer Science/Database

[Database] ElephantSQL 데이터베이스 배포 및 연결

Bay Im 2024. 1. 12. 20:08
ElephantSQL 데이터베이스 연결 
  • 스프링 부트 프로젝트 ElephantSQL 데이터베이스 연결
    • ElephantSQL 가입
    • 인스턴스 생성
    • build.gradle 의존성 추가 (기존에 있던 mysql은 주석 처리)
    implementation 'org.postgresql:postgresql:42.2.2' // 추가
    	runtimeOnly 'org.postgresql:postgresql' // 추가
    
    • application.yml 수정
    spring:
      datasource:
        url: jdbc:postgresql://floppy.db.elephantsql.com:5432/(username)
        username: (username)
        password: 
        driver-class-name: org.postgresql.Driver
    
    	jpa:
        hibernate:
          ddl-auto: create
        properties:
          hibernate:
            database: postgresql
            database-platform: org.hibernate.dialect.PostgreSQLDialect
            format_sql: true
            use_sql_comments: true
            show_sql: true
    ​
     
  • 연결 완료 및 테이블 생성 확인
  • 프로젝트 실행 시 DB에 데이터 들어가는지 확인