SpringBoot使用数据库

这一篇简单介绍一下SpringBoot配置数据库的配置(依赖和application.properties),以下全是以本地数据库为例子,具体用户名密码地址都根据实际去修改。

Mysql数据库:

pom文件:

dependency

groupIdmysql/groupId

artifactIdmysql-connector-java/artifactId

scoperuntime/scope

/dependency

application.properties:

##数据库地址

spring.datasource.url=jdbc:mysql://localhost:3306/test?characterEncoding=utf8useSSL=false

##数据库用户名

spring.datasource.username=root

##数据库密码

spring.datasource.password=root

##数据库驱动

spring.datasource.driver-class-name=com.mysql.jdbc.Driver

Sql Server数据库:

pom文件:

dependency

groupIdcom.microsoft.sqlserver/groupId

artifactIdmssql-jdbc/artifactId

scoperuntime/scope

/dependency

application.properties:

##数据库地址

spring.datasource.url=jdbc:sqlserver://192.168.16.218:1433;databaseName=dev_btrpawn

##数据库用户名

spring.datasource.username=sa

##数据库密码

spring.datasource.password=p@ssw0rd

##数据库驱动

spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver

oracle数据库:

没有找到仓库中oracle得jar 需要自己下载然后加入

application.properties:

spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver

spring.datasource.url=jdbc:oracle:thin:@localhost:1521:orcl

spring.datasource.username=dalaoyang

spring.datasource.password=dalaoyang123

mongodb数据库:

pom文件:

dependencies

dependency

groupIdorg.springframework.boot/groupId

artifactIdspring-boot-starter-data-mongodb/artifactId

/dependency

/dependencies

application.properties:

spring.data.mongodb.uri=mongodb://localhost:27017/test

h2数据库:

pom文件:

dependency

groupIdcom.h2database/groupId

artifactIdh2/artifactId

scoperuntime/scope

/dependency

application.properties:

spring.datasource.url=jdbc:h2:file:D:/roncoo_h2/roncoo_spring_boot;AUTO_SERVER=TRUE;DBCLOSE_ON_EXIT=FALSE

spring.datasource.username=sa

spring.datasource.password=

猜你喜欢

转载自www.cnblogs.com/qfjavabd/p/10471605.html