首页 > 数据库技术 > 详细

php转java 系列2 Spring boo 链接数据库jdbc

时间:2020-04-19 11:30:28      阅读:43      评论:0      收藏:0      [点我收藏+]

php转java 系列2 Spring boo 链接数据库jdbc

 

JDBC 
首先创建一个新项目,在创建项目时要注意导入依赖,

 技术分享图片

 

 

在项目创建成功后就会看到在 pom.xml 文件中找到,但是如果在创建项目的时候没有导入,就要在pom.xml中手动的添加依赖;

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

 


连接数据库
在连接数据库之后,编写数据库配置文件


#访问根路径

#应用名称
spring.application.name=springboot-demo

#访问端口号
server.port=8080

#编码格式
server.tomcat.uri-encoding=utf-8

#数据库相关配置
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://115.29.223.160:3306/wangzhan
spring.datasource.username=zhangwei
spring.datasource.password=zhang111
spring.datasource.max-idle=10
spring.datasource.max-wait=10000
spring.datasource.min-idle=5
spring.datasource.initial-size=5

#session生命周期

server.servlet.session.timeout=30m

 

php转java 系列2 Spring boo 链接数据库jdbc

原文:https://www.cnblogs.com/newmiracle/p/12730721.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!