#Spring JdbcTemplate入門@FDDLC
pom.xml的內容:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>P031_HelloJdbcTemplate</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.16</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.8.RELEASE</version>
</dependency>
</dependencies>
</project>
Main.java的內容:
package cn.liuxingchang;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
public class Main {
public static void main(String[] args) {
//1、準備資料來源:這裡使用Spring內建的資料來源
DriverManagerDataSource dataSource = new DriverManagerDataSource();
//2、設定資料庫的相關屬性
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/test?characterEncoding=UTF8&serverTimezone=Asia/Shanghai";
dataSource.setUrl(url);
dataSource.setUsername("root");
dataSource.setPassword("123456");
//3、新建JdbcTemplate,並繫結資料來源
JdbcTemplate template = new JdbcTemplate(dataSource);
//4、進行CRUD操作
template.execute("update account set money = 400 where id = 4");
}
}
相關文章
- #SpringBoot入門程式 @FDDLCSpring Boot
- #純註解小專案:JdbcTemplate、SpEL@Transactional@PropertySource@EnableTransactionManagement#spring-tx@FDDLCJDBCSpring
- Spring框架|整合JdbcTemplateSpring框架JDBC
- Spring 的 JdbcTemplate 和 JdbcDaoSupportSpringJDBC
- Spring Boot入門系列(十四)使用JdbcTemplate運算元據庫,配置多資料來源!Spring BootJDBC
- Spring JdbcTemplate之使用詳解SpringJDBC
- Spring 系列之jdbcTemplate的使用SpringJDBC
- Spring 入門Spring
- spring下 -spring整體架構,JdbcTemplate筆記Spring架構JDBC筆記
- Spring04——Spring操作JdbcTemplate進行JDBC操作SpringJDBC
- Spring入門指南Spring
- spring 快速入門Spring
- spring入門(二)Spring
- Spring Boot入門Spring Boot
- 1、Spring入門Spring
- 入門Spring6Spring
- Spring Boot HttpExchange 入門Spring BootHTTP
- spring boot快速入門Spring Boot
- Spring Security 入門篇Spring
- spring mvc 快速入門SpringMVC
- Spring Boot Dubbo 入門Spring Boot
- spring入門學習Spring
- Spring Security 快速入門Spring
- Spring Security(一)入門Spring
- Spring MVC 入門程式SpringMVC
- Spring Cloud Gateway 入門SpringCloudGateway
- Spring Cloud Gateway入門 - spring.ioSpringCloudGateway
- Spring入門(一):建立Spring專案Spring
- SpringBoot2.x入門教程:引入jdbc模組與JdbcTemplate簡單使用Spring BootJDBC
- spring入門aop和iocSpring
- Spring Cloud Alibaba入門篇SpringCloud
- Go-Spring入門篇GoSpring
- Spring入門配置(一) - IOCSpring
- Spring Shell入門介紹Spring
- IDEA下——Spring入門程式IdeaSpring
- Spring Boot (一)快速入門Spring Boot
- Spring Boot 2.0.1 入門教程Spring Boot
- Spring Boot整合hessian入門Spring Boot