SpringBoot使⽤JDBC连接Mysql数据库1.环境
win10
jdk13
Eclipse IDE for Enterprise Java Developers Version: 2019-12 (4.14.0)
apache-maven-3.6.3
mysql-8.0.19-winx64
2.创建数据库,建表
建表,插⼊数据
DROP TABLE IF EXISTS`student`;
CREATE TABLE`student`(
`ID`int(0)NOT NULL AUTO_INCREMENT,
`AGE`int(0)NULL DEFAULT NULL,
`NAME`varchar(50)CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT'',
`SCORE_SUM`varchar(50)CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT'',
`SCORE_AVG`varchar(50)CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT'',
PRIMARY KEY(`ID`)USING BTREE
)ENGINE=InnoDB CHARACTER SET= utf8 COLLATE= utf8_bin ROW_FORMAT = Dynamic;
INSERT INTO`student`VALUES(1,18,'stu1','700','100');
3.创建springboot项⽬
加载完成
4.创建相关⽂件以及配置
注意:开发中⽤到lombok 注解,需先安装插件,
l配置
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.12.RELEASE</version>
<relativePath/><!-- lookup parent from repository -->
</parent>
<groupId&le</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<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>
<!--lombok 注解引⼊依赖,安装插件⽅可使⽤-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<!-- <version>1.16.10</version> -->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
jdbctemplate查询一条数据<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论