一、JDBC_事务

通过JDBC来操作银行转账的事务

1.API介绍

    Connection接口中与事务有关的方法
void setAutoCommit(boolean autoCommit) throws SQLException;
false:开启事务, ture:关闭事务
void commit() throws SQLException;
提交事务
void rollback() throws SQLException;
回滚事务
 
 
 
6
 
 
 
 
 
1
void setAutoCommit(boolean autoCommit) throws SQLException;
2
false:开启事务, ture:关闭事务
3
void commit() throws SQLException;
4
提交事务
5
void rollback() throws SQLException;
6
回滚事务
 
 
案例:
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException; public class JDBCTransactionTest {
public static void main(String[] args) { Connection conn = null;
PreparedStatement stmt = null; try {
// 1. 获取连接对象
conn = JDBCUtils.getConnection(); // 第一步 : 开启事务
conn.setAutoCommit(false); // 2. 操作数据
// 2.1 账户转出
String outSql = "update account set money = money - ? where name = ?;";
stmt = conn.prepareStatement(outSql);
stmt.setInt(1, 1000);
stmt.setString(2, "tom");
stmt.executeUpdate(); // 模拟异常 ...
// int num = 10 / 0; // 2.2 账户转入
String inSql = "update account set money = money + ? where name = ?;";
stmt = conn.prepareStatement(inSql);
stmt.setInt(1, 1000);
stmt.setString(2, "jery");
stmt.executeUpdate(); // 第二步 : 提交事务
conn.commit(); System.out.println("转账成功!"); } catch (Exception e) {
// 如果出现异常, 需要进行事务回滚.
// 第三步 : 回滚事务
try {
conn.rollback();
} catch (SQLException e1) {
e1.printStackTrace();
} System.out.println("转账失败!"); } finally {
// 3. 释放资源
JDBCUtils.release(conn, stmt);
}
}
}
 
 
 
57
 
 
 
 
 
1
import java.sql.Connection;
2
import java.sql.PreparedStatement;
3
import java.sql.SQLException;
4

5
public class JDBCTransactionTest {
6
    public static void main(String[] args) {
7

8
        Connection conn = null;
9
        PreparedStatement stmt = null;
10

11
        try {
12
            // 1. 获取连接对象
13
            conn = JDBCUtils.getConnection();
14

15
            // 第一步 : 开启事务
16
            conn.setAutoCommit(false);
17

18
            // 2. 操作数据
19
            // 2.1 账户转出
20
            String outSql = "update account set money = money - ? where name = ?;";
21
            stmt = conn.prepareStatement(outSql);
22
            stmt.setInt(1, 1000);
23
            stmt.setString(2, "tom");
24
            stmt.executeUpdate();
25

26
            // 模拟异常 ...
27
            // int num = 10 / 0;
28

29
            // 2.2 账户转入
30
            String inSql = "update account set money = money + ? where name = ?;";
31
            stmt = conn.prepareStatement(inSql);
32
            stmt.setInt(1, 1000);
33
            stmt.setString(2, "jery");
34
            stmt.executeUpdate();
35

36
            // 第二步 : 提交事务
37
            conn.commit();
38

39
            System.out.println("转账成功!");
40

41
        } catch (Exception e) {
42
            // 如果出现异常, 需要进行事务回滚.
43
            // 第三步 : 回滚事务
44
            try {
45
                conn.rollback();
46
            } catch (SQLException e1) {
47
                e1.printStackTrace();
48
            }
49

50
            System.out.println("转账失败!");
51

52
        } finally {
53
            // 3. 释放资源
54
            JDBCUtils.release(conn, stmt);
55
        }
56
    }
57
}
 
 
 
 
 

二、jdbcTemplate

1.API介绍

    org.springframework.jdbc.core.JdbcTemplate类方便执行SQL语句
public JdbcTemplate(DataSource dataSource)
创建JdbcTemplate对象,方便执行SQL语句
public void execute(final String sql)
execute可以执行所有SQL语句,因为没有返回值,一般用于执行DML语句。
 
 
 
4
 
 
 
 
 
1
public JdbcTemplate(DataSource dataSource)
2
创建JdbcTemplate对象,方便执行SQL语句
3
public void execute(final String sql)
4
execute可以执行所有SQL语句,因为没有返回值,一般用于执行DML语句。
 
 
 

2.使用步骤

        1. 准备DruidDataSource连接池
2. 导入依赖的jar包
   - spring-beans-5.0.2.RELEASE.jar
   - spring-core-5.0.2.RELEASE.jar
   - spring-jdbc-5.0.2.RELEASE.jar
   - spring-tx-5.0.2.RELEASE.jar
   - com.springsource.org.apache.commons.logging-1.1.1.jar
3. 创建JdbcTemplate对象,传入c3p0连接池
4. 调用execute、update、queryXxx等方法

3.案例

    (1)c3p0-config.xml配置文件
        
<?xml version="1.0" encoding="UTF-8"?>
<c3p0-config>
<!-- 默认配置,c3p0框架默认加载这段默认配置 -->
<default-config>
<!-- 配置JDBC 四个基本属性 -->
<property name="driverClass">com.mysql.cj.jdbc.Driver</property>
<property name="jdbcUrl">jdbc:mysql://localhost:3306/mydb?serverTimezone=UTC&amp;characterEncoding=utf-8</property>
<property name="user">root</property>
<property name="password">111</property>
</default-config>
<!-- 可以自定义配置,为这段配置起一个名字,c3p0指定名称加载配置 -->
<named-config name="xxxxx">
<property name="driverClass">com.mysql.cj.jdbc.Driver</property>
<property name="jdbcUrl">jdbc:mysql://localhost:3306/mydb?serverTimezone=UTC&amp;characterEncoding=utf-8</property>
<property name="user">root</property>
<property name="password">111</property>
</named-config>
</c3p0-config>
 
 
 
18
 
 
 
 
 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<c3p0-config>
3
    <!-- 默认配置,c3p0框架默认加载这段默认配置 -->
4
    <default-config>
5
        <!-- 配置JDBC 四个基本属性 -->
6
        <property name="driverClass">com.mysql.cj.jdbc.Driver</property>
7
        <property name="jdbcUrl">jdbc:mysql://localhost:3306/mydb?serverTimezone=UTC&amp;characterEncoding=utf-8</property>
8
        <property name="user">root</property>
9
        <property name="password">111</property>
10
    </default-config>
11
    <!-- 可以自定义配置,为这段配置起一个名字,c3p0指定名称加载配置 -->
12
    <named-config name="xxxxx">
13
        <property name="driverClass">com.mysql.cj.jdbc.Driver</property>
14
        <property name="jdbcUrl">jdbc:mysql://localhost:3306/mydb?serverTimezone=UTC&amp;characterEncoding=utf-8</property>
15
        <property name="user">root</property>
16
        <property name="password">111</property>
17
    </named-config>
18
</c3p0-config>
 
 
        (2)JDBCUtils工具类
public class JDBCUtils {

    // 核心连接池类
private static ComboPooledDataSource dataSource = new ComboPooledDataSource(); public static DataSource getDataSource() {
return dataSource;
} // 获取连接
public static Connection getConnection() throws SQLException {
return dataSource.getConnection();
} // 释放资源
public static void release(Connection conn, Statement stmt, ResultSet rs) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
rs = null;
} release(conn, stmt);
} public static void release(Connection conn, Statement stmt) {
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
stmt = null;
} if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
conn = null;
}
}
}
 
 
 
48
 
 
 
 
 
1
public class JDBCUtils {
2

3
    // 核心连接池类
4
    private static ComboPooledDataSource dataSource = new ComboPooledDataSource();
5

6
    public static DataSource getDataSource() {
7
        return dataSource;
8
    }
9

10
    // 获取连接
11
    public static Connection getConnection() throws SQLException {
12
        return dataSource.getConnection();
13
    }
14

15
    // 释放资源
16
    public static void release(Connection conn, Statement stmt, ResultSet rs) {
17
        if (rs != null) {
18
            try {
19
                rs.close();
20
            } catch (SQLException e) {
21
                e.printStackTrace();
22
            }
23
            rs = null;
24
        }
25

26
        release(conn, stmt);
27
    }
28

29
    public static void release(Connection conn, Statement stmt) {
30
        if (stmt != null) {
31
            try {
32
                stmt.close();
33
            } catch (SQLException e) {
34
                e.printStackTrace();
35
            }
36
            stmt = null;
37
        }
38

39
        if (conn != null) {
40
            try {
41
                conn.close();
42
            } catch (SQLException e) {
43
                e.printStackTrace();
44
            }
45
            conn = null;
46
        }
47
    }
48
}
 
 
jdbcTemplate的exeucte方法
public class JDBCTemplateExecute {
public static void main(String[] args) { // 1. 创建表的SQL语句
String sql = "create table product (" +
"pid int primary key auto_increment," +
"pname varchar(20)," +
"price double" +
");"; // 2. 创建 jdbcTemplate 对象, 并将数据库连接池作为参数传入
JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource()); // 3. 使用 jdbcTemplate 对象调用 execute 方法, 执行 sql 语句, 创建数据库表.
jdbcTemplate.execute(sql);
}
}
 
 
 
17
 
 
 
 
 
1
public class JDBCTemplateExecute {
2
public static void main(String[] args) {
3

4
        // 1. 创建表的SQL语句
5
        String sql = "create table product (" +
6
                "pid int primary key auto_increment," +
7
                "pname varchar(20)," +
8
                "price double" +
9
                ");";
10

11
        // 2. 创建 jdbcTemplate 对象, 并将数据库连接池作为参数传入
12
JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource());
13

14
// 3. 使用 jdbcTemplate 对象调用 execute 方法, 执行 sql 语句, 创建数据库表.
15
jdbcTemplate.execute(sql);
16
}
17
}
 
 

4通过jdbcTemplate实现增删改

    API介绍
    
// org.springframework.jdbc.core.JdbcTemplate类方便执行SQL语句
public int update(final String sql)
用于执行`INSERT`、`UPDATE`、`DELETE`等DML语句
 
 
 
5
 
 
 
 
 
1
// org.springframework.jdbc.core.JdbcTemplate类方便执行SQL语句
2
public int update(final String sql)
3
用于执行`INSERT`、`UPDATE`、`DELETE`等DML语句
4

5

 
 
使用步骤:
 
1.创建JdbcTemplate对象
2.编写SQL语句
3.使用JdbcTemplate对象的update方法进行增删改
 
insert 增加数据 :
   @Test
public void insert() { // 1. 创建一个 JdbcTemplate 对象, 并将连接池作为参数传入
JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource()); // 2. 编写 sql 语句
String sql = "insert into product values(null, ?, ?);"; // 3. 执行 update 方法.
jdbcTemplate.update(sql, "iPhone3GS", 3333);
jdbcTemplate.update(sql, "iPhone4", 5000);
jdbcTemplate.update(sql, "iPhone4S", 5001);
jdbcTemplate.update(sql, "iPhone5", 5555);
jdbcTemplate.update(sql, "iPhone5C", 3888);
jdbcTemplate.update(sql, "iPhone5S", 5666);
jdbcTemplate.update(sql, "iPhone6", 6666);
jdbcTemplate.update(sql, "iPhone6S", 7000);
jdbcTemplate.update(sql, "iPhone6SP", 7777);
jdbcTemplate.update(sql, "iPhoneX", 8888);
}
 
 
 
21
 
 
 
 
 
1
   @Test
2
    public void insert() {
3

4
        // 1. 创建一个 JdbcTemplate 对象, 并将连接池作为参数传入
5
        JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource());
6

7
        // 2. 编写 sql 语句
8
        String sql = "insert into product values(null, ?, ?);";
9

10
        // 3. 执行 update 方法.
11
        jdbcTemplate.update(sql, "iPhone3GS", 3333);
12
        jdbcTemplate.update(sql, "iPhone4", 5000);
13
        jdbcTemplate.update(sql, "iPhone4S", 5001);
14
        jdbcTemplate.update(sql, "iPhone5", 5555);
15
        jdbcTemplate.update(sql, "iPhone5C", 3888);
16
        jdbcTemplate.update(sql, "iPhone5S", 5666);
17
        jdbcTemplate.update(sql, "iPhone6", 6666);
18
        jdbcTemplate.update(sql, "iPhone6S", 7000);
19
        jdbcTemplate.update(sql, "iPhone6SP", 7777);
20
        jdbcTemplate.update(sql, "iPhoneX", 8888);
21
    }
 
 
update 修改数据 :*
    @Test
public void update() { // 1. 创建一个 JdbcTemplate 对象, 并将数据库连接池作为参数传入
JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource()); // 2. 执行 update 语句
String sql = "update product set pname = ?, price = ? where pid = ?;";
int count = jdbcTemplate.update(sql, "XVIII", 18888, 10);
System.out.println("count = " + count);
}
 
 
 
11
 
 
 
 
 
1
    @Test
2
    public void update() {
3

4
        // 1. 创建一个 JdbcTemplate 对象, 并将数据库连接池作为参数传入
5
        JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource());
6

7
        // 2. 执行 update 语句
8
        String sql = "update product set pname = ?, price = ? where pid = ?;";
9
        int count = jdbcTemplate.update(sql, "XVIII", 18888, 10);
10
        System.out.println("count = " + count);
11
    }
 
 
delete 删除数据 :
    @Test
public void delete() {
// 1. 创建一个 JdbcTemplate 对象, 并将数据库连接池作为参数传入
JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource()); // 2. 执行 delete 操作
String sql = "delete from product where pid = ?;";
int count = jdbcTemplate.update(sql, 7);
System.out.println("count = " + count);
}
 
 
 
10
 
 
 
 
 
1
    @Test
2
    public void delete() {
3
        // 1. 创建一个 JdbcTemplate 对象, 并将数据库连接池作为参数传入
4
        JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource());
5

6
        // 2. 执行 delete 操作
7
        String sql = "delete from product where pid = ?;";
8
        int count = jdbcTemplate.update(sql, 7);
9
        System.out.println("count = " + count);
10
    }
 
 
 

小结:

JdbcTemplate的update方法用于执行DML语句。同时还可以在SQL语句中使用?占位,在update方法的Object... args可变参数中传入对应的参数。
 

5 jdbcTemplate实现查询

    API介绍
     queryForObject返回一个指定类型
    
// 单行单列的查询
public <T> T queryForObject(String sql, Class<T> requiredType, Object... args):
传入参数, 执行查询语句,返回一个指定类型的数据。 // 单行多列
public Map<String, Object> queryForMap(String sql, Object... args)
传入参数,执行查询语句,将一条记录放到一个Map中。 // 多行多列
public List<Map<String, Object>> queryForList(String sql, Object... args)
传入参数,执行查询语句,返回一个List集合,List中存放的是Map类型的数据。 // 返回一个List 存放对象数据
public <T> List<T> query(String sql, RowMapper<T> rowMapper)
执行查询语句,返回一个List集合,List中存放的是RowMapper指定类型的数据。 // 提供了一个上述方法的一个实现类 RowMapper 行映射接口 BeanPropertyRowMapper 实体类属性行映射
public class BeanPropertyRowMapper<T> implements RowMapper<T>
BeanPropertyRowMapper类实现了RowMapper接口
实体类属性行映射
 
 
16
 
 
 
1
// 单行单列的查询
2
public <T> T queryForObject(String sql, Class<T> requiredType, Object... args):
3
   传入参数, 执行查询语句,返回一个指定类型的数据。
4

5
// 单行多列
6
public Map<String, Object> queryForMap(String sql, Object... args)
7
传入参数,执行查询语句,将一条记录放到一个Map中。
8

9
// 多行多列
10
public List<Map<String, Object>> queryForList(String sql, Object... args)
11
传入参数,执行查询语句,返回一个List集合,List中存放的是Map类型的数据。
12

13
// 返回一个List 存放对象数据
14
public <T> List<T> query(String sql, RowMapper<T> rowMapper)
15
执行查询语句,返回一个List集合,List中存放的是RowMapper指定类型的数据。
16

 
 
17
// 提供了一个上述方法的一个实现类     RowMapper 行映射接口     BeanPropertyRowMapper     实体类属性行映射
18
public class BeanPropertyRowMapper<T> implements RowMapper<T>
19
BeanPropertyRowMapper类实现了RowMapper接口
 
 
    
    @Test
public void test1() { // 1. 创建一个 JdbcTemplate 对象
JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource()); // 2. 执行 queryForObject 方法
String sql = "select pname from product where price = 7777";
String pname = jdbcTemplate.queryForObject(sql, String.class);
System.out.println("pname = " + pname);
} @Test
public void test2() { // 1. 创建一个 JdbcTemplate 对象
JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource()); // 2. 执行 queryForMap 方法
String sql = "select * from product where pid = ?;";
Map<String, Object> map = jdbcTemplate.queryForMap(sql, 6);
System.out.println("map = " + map);
} @Test
public void test3() { // 1. 创建一个 JdbcTemplate 对象
JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource()); // 2. 执行 objectForList 方法
String sql = "select * from product where pid < ?;";
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, 8);
for (Map<String, Object> map : list) {
System.out.println(map);
}
} @Test
public void test4() { // 1. 创建一个 JdbcTemplate 对象
JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource()); // 2. 执行 query 方法
String sql = "select * from product;";
List<Product> list = jdbcTemplate.query(sql, new RowMapper<Product>() {
@Override
public Product mapRow(ResultSet rs, int i) throws SQLException { Product product = new Product();
int pid = rs.getInt("pid");
String pname = rs.getString("pname");
double price = rs.getDouble("price");
product.setPid(pid);
product.setPname(pname);
product.setPrice(price); return product;
}
}); // 遍历 list 集合
for (Product product : list) {
System.out.println(product);
}
} @Test
public void test5() { // 1. 创建一个 JdbcTemplate 对象
JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource()); // 2. 执行 query 方法
String sql = "select * from product;";
List<Product> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Product.class)); // 3. 遍历 list 集合
for (Product product : list) {
System.out.println(product);
}
}
 
 
 
x
 
 
 
 
 
1
    @Test
2
    public void test1() {
3

4
        // 1. 创建一个 JdbcTemplate 对象
5
        JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource());
6

7
        // 2. 执行 queryForObject 方法
8
        String sql = "select pname from product where price = 7777";
9
        String pname = jdbcTemplate.queryForObject(sql, String.class);
10
        System.out.println("pname = " + pname);
11
    }
12

13
    @Test
14
    public void test2() {
15

16
        // 1. 创建一个 JdbcTemplate 对象
17
        JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource());
18

19
        // 2. 执行 queryForMap 方法
20
        String sql = "select * from product where pid = ?;";
21
        Map<String, Object> map = jdbcTemplate.queryForMap(sql, 6);
22
        System.out.println("map = " + map);
23
    }
24

25
    @Test
26
    public void test3() {
27

28
        // 1. 创建一个 JdbcTemplate 对象
29
        JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource());
30

31
        // 2. 执行 objectForList 方法
32
        String sql = "select * from product where pid < ?;";
33
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, 8);
34
        for (Map<String, Object> map : list) {
35
            System.out.println(map);
36
        }
37
    }
38

39

40

41
    @Test
42
    public void test4() {
43

44
        // 1. 创建一个 JdbcTemplate 对象
45
        JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource());
46

47
        // 2. 执行 query 方法
48
        String sql = "select * from product;";
49
        List<Product> list = jdbcTemplate.query(sql, new RowMapper<Product>() {
50
            @Override
51
            public Product mapRow(ResultSet rs, int i) throws SQLException {
52

53
                Product product = new Product();
54
                int pid = rs.getInt("pid");
55
                String pname = rs.getString("pname");
56
                double price = rs.getDouble("price");
57
                product.setPid(pid);
58
                product.setPname(pname);
59
                product.setPrice(price);
60

61
                return product;
62
            }
63
        });
64

65
        // 遍历 list 集合
66
        for (Product product : list) {
67
            System.out.println(product);
68
        }
69
    }
70

71

72

73
    @Test
74
    public void test5() {
75

76
        // 1. 创建一个 JdbcTemplate 对象
77
        JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource());
78

79
        // 2. 执行 query 方法
80
        String sql = "select * from product;";
81
        List<Product> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Product.class));
82

83
        // 3. 遍历 list 集合
84
        for (Product product : list) {
85
            System.out.println(product);
86
        }
87
    }
 
 

小结:

      JDBCTemplate的query方法用于执行SQL语句,简化JDBC的代码。同时还可以在SQL语句中使用?占位,在query方法的Object... args可变参数中传入对应的参数。  
 
 
 
 
 
 
 
 
 
 
 
 
 
 

<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">

 
 
 
 

21JDBC_事务&JDBCTemplate的更多相关文章

  1. CSDN上看到的一篇有关Spring JDBC事务管理的文章(内容比较全) (转)

    JDBC事务管理 Spring提供编程式的事务管理(Programmatic transaction manage- ment)与声明式的事务管理(Declarative transaction ma ...

  2. 春天JDBC事务管理

    JDBC事务管理 春天提供编程式的事务管理(编程式事务管理)与声明式的事务管理(声明式事务management),为不同的事务实现提供了一致的编程模型,这节以JDBC事务为例,介绍Spring的事务管 ...

  3. Mysql事务开启方式(客户端+java手动+Spring Boot)

    一:概念 作为单个逻辑单元执行一系列操作,要么完全执行,要么完全不执行.举例 我们需要向数据库插入3条数据(我们希望这三条数据要么全部插入成功,要么全部失败), 比如第一条数据插入成功,插入第二条数据 ...

  4. 【Spring实战】—— 16 基于JDBC持久化的事务管理

    前面讲解了基于JDBC驱动的Spring的持久化管理,本篇开始则着重介绍下与事务相关的操作. 通过本文你可以了解到: 1 Spring 事务管理的机制 2 基于JDBC持久化的事务管理 Spring的 ...

  5. Spring笔记(4) - Spring的编程式事务和声明式事务详解

    一.背景 事务管理对于企业应用而言至关重要.它保证了用户的每一次操作都是可靠的,即便出现了异常的访问情况,也不至于破坏后台数据的完整性.就像银行的自助取款机,通常都能正常为客户服务,但是也难免遇到操作 ...

  6. Spring 学习,看松哥这一篇万余字干货就够了!

    1. Spring 简介 我们常说的 Spring 实际上是指 Spring Framework,而 Spring Framework 只是 Spring 家族中的一个分支而已.那么 Spring 家 ...

  7. 单点突破:Spring(上)

    Spring概述 ​ 我们常说的 Spring 实际上是指 Spring Framework,而 Spring Framework 只是 Spring 家族中的一个分支而已.Spring 是为了解决企 ...

  8. 【Java EE 学习 52】【Spring学习第四天】【Spring与JDBC】【JdbcTemplate创建的三种方式】【Spring事务管理】【事务中使用dbutils则回滚失败!!!??】

    一.JDBC编程特点 静态代码+动态变量=JDBC编程. 静态代码:比如所有的数据库连接池 都实现了DataSource接口,都实现了Connection接口. 动态变量:用户名.密码.连接的数据库. ...

  9. JdbcTemplate与事务

    JdbcTemplate操作采用的是JDBC默认的AutoCommit模式,也就是说我们还无法保证数据操作的原子性(要么全部生效,要么全部无效),如: JdbcTemplate jdbcTemplat ...

随机推荐

  1. 如何在同一台电脑上启动多个Tomcat服务器

    安装第二个tomcat完成后,到安装目录下的conf子目录中打开server.xml文件,查找以下三处: (1)修改http范围端口(默认为8080端口) <Connector port=&qu ...

  2. sql存储过程中使用 output、nvarchar(max)

    1.sql存储过程中使用 output CREATE PROCEDURE [dbo].[P_Max] @a int, -- 输入 @b int, -- 输入 @Returnc int output - ...

  3. Python学习第十二篇——切片的使用

    Python中使用函数切片可以创建副本,保留原本.现在给出如下代码 magicians_list = ['mole','jack','lucy'] new_lists = [] def make_gr ...

  4. NFV论文集(三)综述

    一 文章名称:Dependability of the NFV Orchestrator: State of the Art and Research Challenges 发表时间:2018 期刊来 ...

  5. jupyter使用

    jupyter使用 安装 在anaconda3的安装路径中,尽量避免使用汉字或者括号. 启动 在Windows上正确安装Anaconda3,确认配置好环境变量,然后再命令行中输入jupyter not ...

  6. JSP 快速入门

    目录 生命周期 9大对象 常用指令 基本语法 表达式语言(EL) jstl介绍 常用的jstl标签 生命周期 我们虽然写的是jsp,代码中包含了html.css.js,以及Java代码,但是真正执行的 ...

  7. Visual Studio 2010 Shortcuts

    Uploaded by ProNotion, updated on 11/28/2013 by jmb Platform: Windows/ English  PDF    Print   Hide ...

  8. 开发工具之Sublime编辑器

    sublime是一款轻量级的编辑器,可以从官网上进行下载最新版本.它有很多使用并且强大的功能支持.例如:GOTO,package 等快捷操作.但有时候下载的版本不能进行安装package contro ...

  9. 5 Http请求中文乱码处理

    java 乱码分很多种,这里主要研究解决http请求中出现乱码的情况. http请求出现中文乱码的主要原因:发送方与接收方编码不一致,服务器默认支持的编码与web应用不一致,如:tomcat 是国外程 ...

  10. [转帖]SAP一句话入门:Material Management

    SAP一句话入门:Material Management http://blog.vsharing.com/MilesForce/A616683.html 让我们来关注供应链上的另一个模块Materi ...