我是靠谱客的博主 兴奋羽毛,这篇文章主要介绍spring-boot jdbc 连接Oracle1.jdbc方式,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154

1.jdbc方式

1.1pom.xml文件配置

复制代码
<!-- oracle mybatis -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.2.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
image.png

1.2application.properties配置

复制代码
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:orcl
spring.datasource.username=admin
spring.datasource.password=admin
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.max-idle=10
spring.datasource.max-wait=10000
spring.datasource.min-idle=5
spring.datasource.initial-size=5

1.3项目目录

image.png

1.4OneController.java

复制代码
package com.shuai.spring_boot_1.web;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class OneController {
@Autowired
private JdbcTemplate jdbcTemplate;
@RequestMapping("/")
@ResponseBody
public String index(){
String sql = "insert into users (id,name) values (1,'zhangsan')";
jdbcTemplate.execute(sql);
System.out.println("执行完成");
return "hello spring boot";
}
}
image.png

1.5App.java

复制代码
package com.shuai.spring_boot_1;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
image.png

1.6运行项目

复制代码
运行App.java中的main方法

1.71.10访问项目

复制代码
http://localhost:8080/


作者:帅哥_刷哥
链接:https://www.jianshu.com/p/7833f084d453
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

最后

以上就是兴奋羽毛最近收集整理的关于spring-boot jdbc 连接Oracle1.jdbc方式的全部内容,更多相关spring-boot内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(72)

评论列表共有 0 条评论

立即
投稿
返回
顶部