File tree Expand file tree Collapse file tree 7 files changed +102
-11
lines changed
java/com/hand/springbootdataaccess
test/java/com/hand/springbootdataaccess Expand file tree Collapse file tree 7 files changed +102
-11
lines changed Original file line number Diff line number Diff line change 20
20
<dependency >
21
21
<groupId >org.springframework.boot</groupId >
22
22
<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 >
34
23
</dependency >
35
24
36
25
<dependency >
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 >
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments