spring-boot jdbc 連線Oracle
阿新 • • 發佈:2019-01-25
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.png1.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.png1.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.png1.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.png1.6執行專案
執行App.java中的main方法
1.71.10訪問專案
http://localhost:8080/
作者:帥哥_刷哥
連結:https://www.jianshu.com/p/7833f084d453
來源:簡書
著作權歸作者所有。商業轉載請聯絡作者獲得授權,非商業轉載請註明出處。