Javaでdbを使用する方法

1491 ワード

JDBCとは?


https://shs2810.tistory.com/18

何が連絡を解除しますか?


https://minkwon4.tistory.com/168

DataSourceとは?


https://deepweller.tistory.com/6

HikariCPとは?


mariadbスプリングガイドで使用する方法


application.properties:データソースの設定
spring.datasource.driverClassName=org.mariadb.jdbc.Driver
spring.datasource.url=jdbc:mariadb://localhost:3306/테이블이름
spring.datasource.username=root
spring.datasource.password=패스워드
build.gralde:次の2つの依存項目を追加
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jdbc
	implementation group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc', version: '2.6.4'


// https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client
	implementation group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '3.0.3'
AppConfig.class:beanの追加
@Configuration
@ComponentScan
public class AutoAppConfig {
    private final DataSource dataSource;

    public AutoAppConfig(DataSource dataSource){
        this.dataSource = dataSource;
    }
}