内容简介:以jdbc的形式访问mysql数据库是比较基础的知识,理解spring boot中如何使用jdbc对我们理解spring boot对mybatis等数据框架是很有意义的。配置数据库相关信息运行结果:
简述
以jdbc的形式访问 mysql 数据库是比较基础的知识,理解spring boot中如何使用jdbc对我们理解spring boot对mybatis等数据框架是很有意义的。
spring boot 整合 jdbc 的步骤
引入 starts 启动器
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> </dependencies>
配置 application.yaml 文件
配置数据库相关信息
spring: datasource: data-username: root data-password: root url: jdbc:mysql://127.0.0.1:3306/sff_test driver-class-name: com.mysql.jdbc.Driver
运行测试
@RunWith(SpringRunner.class) @SpringBootTest public class SpringBootJdbcApplicationTests { @Autowired private DataSource dataSource; @Test public void testDataSource() throws SQLException { System.out.println("dataSource类型:" + dataSource.getClass()); Connection connection = dataSource.getConnection(); System.out.println("connection连接:" + connection); connection.close(); } }
运行结果:
从结果中可以看到 spring boot 的 2.1.2.RELEASE 版本默认使用 com.zaxxer.hikari.HikariDataSource
作为数据源。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- SpringBoot整合MongoDB多数据源
- 数据源管理 | PostgreSQL环境整合,JSON类型应用
- 框架—SpringBoot整合Mybatis使用Druid数据源
- SpringBoot2 整合JTA组件,多数据源事务管理
- Spring Boot 2 配置多数据源,整合 MybatisPlus 增强插件
- 【springboot spring mybatis】看我怎么将springboot与spring整合mybatis与druid数据源
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
An Introduction to Genetic Algorithms
Melanie Mitchell / MIT Press / 1998-2-6 / USD 45.00
Genetic algorithms have been used in science and engineering as adaptive algorithms for solving practical problems and as computational models of natural evolutionary systems. This brief, accessible i......一起来看看 《An Introduction to Genetic Algorithms》 这本书的介绍吧!