[DB] SpringBoot + MariaDB 설정

박이레·2023년 8월 2일
0

DB

목록 보기
2/2
post-thumbnail

application.properties

spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
spring.datasource.url=jdbc:mariadb://localhost:{port}/{databaseName}?&serverTimezone=UTC&autoReconnect=true&allowMultiQueries=true&characterEncoding=UTF-8
spring.datasource.username={username}
spring.datasource.password={password}

application.yml

spring:
  datasource:
    driver-class-name: org.mariadb.jdbc.Driver
    url: jdbc:mariadb://localhost:{port}/{databaseName}?&serverTimezone=UTC&autoReconnect=true&allowMultiQueries=true&characterEncoding=UTF-8
    username: {username}
    password: {password}

Connection Test

package com.example.demo;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.sql.Connection;
import java.sql.DriverManager;

public class ConnectionTests {

    @Test
    public void DBTest() throws Exception {

        Class.forName("org.mariadb.jdbc.Driver");

        Connection connection = DriverManager.getConnection(
                "jdbc:mariadb://localhost:{port}/{databaseName}",
                "{username}",
                "{password}");

        Assertions.assertNotNull(connection);

        connection.close();
    }
}
profile
혜화동 사는 Architect

1개의 댓글

comment-user-thumbnail
2023년 8월 2일

공감하며 읽었습니다. 좋은 글 감사드립니다.

답글 달기