Skip to content

Commit 940f1e2

Browse files
author
曾梓健
committed
数据库连接池
1 parent 78810af commit 940f1e2

File tree

7 files changed

+102
-11
lines changed

7 files changed

+102
-11
lines changed

myTest/pom.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,6 @@
2020
<dependency>
2121
<groupId>org.springframework.boot</groupId>
2222
<artifactId>spring-boot-starter-web</artifactId>
23-
<exclusions>
24-
<exclusion>
25-
<!--移除spring-boot-starter-web中的tomcat依赖-->
26-
<groupId>org.springframework.boot</groupId>
27-
<artifactId>spring-boot-starter-tomcat</artifactId>
28-
</exclusion>
29-
</exclusions>
30-
</dependency>
31-
<dependency>
32-
<groupId>org.springframework.boot</groupId>
33-
<artifactId>spring-boot-starter-jetty</artifactId>
3423
</dependency>
3524

3625
<dependency>
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar

springboot-dataaccess/pom.xml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.2.9.RELEASE</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>com.hand</groupId>
12+
<artifactId>springboot-dataaccess</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>springboot-dataaccess</name>
15+
<description>springboot-dataaccess</description>
16+
<properties>
17+
<java.version>8</java.version>
18+
</properties>
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.springframework.boot</groupId>
22+
<artifactId>spring-boot-starter</artifactId>
23+
</dependency>
24+
25+
<dependency>
26+
<groupId>mysql</groupId>
27+
<artifactId>mysql-connector-java</artifactId>
28+
<scope>runtime</scope>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot-starter-test</artifactId>
33+
<scope>test</scope>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.springframework.boot</groupId>
37+
<artifactId>spring-boot-starter-jdbc</artifactId>
38+
</dependency>
39+
</dependencies>
40+
41+
<build>
42+
<plugins>
43+
<plugin>
44+
<groupId>org.springframework.boot</groupId>
45+
<artifactId>spring-boot-maven-plugin</artifactId>
46+
</plugin>
47+
</plugins>
48+
</build>
49+
50+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.hand.springbootdataaccess;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class SpringbootDataaccessApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(SpringbootDataaccessApplication.class, args);
11+
}
12+
13+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
2+
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/sqlfather?useUnicode=true&characterEncoding=utf-8&useSSL=false&useInformationSchema=true
3+
spring.datasource.username=root
4+
spring.datasource.password=123456
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.hand.springbootdataaccess;
2+
3+
import java.sql.Connection;
4+
import java.sql.DatabaseMetaData;
5+
import java.sql.ResultSet;
6+
import java.sql.SQLException;
7+
import java.sql.Statement;
8+
import javax.sql.DataSource;
9+
10+
import org.junit.jupiter.api.Test;
11+
import org.junit.runner.RunWith;
12+
import org.springframework.beans.factory.annotation.Autowired;
13+
import org.springframework.boot.test.context.SpringBootTest;
14+
import org.springframework.test.context.junit4.SpringRunner;
15+
16+
@SpringBootTest
17+
@RunWith(SpringRunner.class)
18+
class SpringbootDataaccessApplicationTests {
19+
20+
@Autowired
21+
private DataSource dataSource;
22+
@Test
23+
void contextLoads() throws SQLException {
24+
Connection connection = dataSource.getConnection();
25+
System.out.println("connection:------" + connection);
26+
Statement statement = connection.createStatement();
27+
ResultSet resultSet = statement.executeQuery("select * from report");
28+
resultSet.next();
29+
System.out.println(resultSet.getString(2));
30+
31+
}
32+
33+
}

0 commit comments

Comments
 (0)