JAVA WEB - JDBC事务开发
2017-06-26 10:40
465 查看
###1.mysql事务操作
*1.Start Transaction 开启事务。
*2.Commit 提交事务。
*3.rollback 回滚事务。
*打开CMD,启动mysql。
*
*1.Start Transaction 开启事务。
*2.Commit 提交事务。
*3.rollback 回滚事务。
1.1.举例说明
*首先在mysql中创建表和数据。CREATE TABLE account( id INT PRIMARY KEY AUTO_INCREMENT, NAME VARCHAR(50), money DOUBLE ); INSERT INTO account(id,NAME,money) VALUES(NULL,'jack',10000); INSERT INTO account(id,NAME,money) VALUES(NULL,'rose',20000);
*打开CMD,启动mysql。
C:\Users\wangfra>mysql -u root -p Enter password: **** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 314 Server version: 5.7.17 MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql +--------------------+ | Database | +--------------------+ | information_schema | | boxuegu | | frank1 | | mydb1 | | mysql | | performance_schema | | sys | | web_db3 | | webdb_1 | | webdb_4 | +--------------------+ Database changed mysql> select * from account; +----+------+-------+ | id | name | money | +----+------+-------+ | 1 | jack | 10000 | | 2 | rose | 20000 | +----+------+-------+ 2 rows in set (0.00 sec) mysql> update account set money = money +1000 where name = 'jack'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update account set money = money +1000 where name = 'jack'; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from account; +----+------+-------+ | id | name | money | +----+------+-------+ | 1 | jack | 12000 | | 2 | rose | 20000 | +----+------+-------+ 2 rows in set (0.00 sec) mysql> start transaction; Query OK, 0 rows affected (0.00 sec) mysql> update account set money = money -1000 where name = 'jack'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from account; +----+------+-------+ | id | name | money | +----+------+-------+ | 1 | jack | 11000 | | 2 | rose | 20000 | +----+------+-------+ 2 rows in set (0.00 sec) mysql> update account set money = money -1000 where name = 'jack'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from account; +----+------+-------+ | id | name | money | +----+------+-------+ | 1 | jack | 10000 | | 2 | rose | 20000 | +----+------+-------+ 2 rows in set (0.00 sec) mysql> update account set money = money + 1000 where name = 'jack'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update account set money = money + 2000 where name = 'jack'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> commit; Query OK, 0 rows affected (0.01 sec) mysql>
*
相关文章推荐
- JAVAWEB开发之事务详解(mysql与JDBC下使用方法、事务的特性、锁机制)和连接池的详细使用(dbcp以c3p0)
- Java EE WEB工程师培训-JDBC+Servlet+JSP整合开发之01.JDBC简介 推荐
- Java EE WEB工程师培训-JDBC+Servlet+JSP整合开发之04.JDBC Resultset 推荐
- Java EE WEB工程师培训-JDBC+Servlet+JSP整合开发之12.Servlet基础(3)
- JavaWeb:JDBC之事务
- java_web学习第十天(JDBC数据库驱动----分页、事务)
- Java EE WEB工程师培训-JDBC+Servlet+JSP整合开发之33.HTML表单 推荐
- Java EE WEB工程师培训-JDBC+Servlet+JSP整合开发之12.Servlet基础(2)
- Java EE WEB工程师培训-JDBC+Servlet+JSP整合开发之16.Cookie
- Java EE WEB工程师培训-JDBC+Servlet+JSP整合开发之13.Form表单处理(2)
- Mybatis前奏【Java Web 开发进化史】——万丈高楼从JDBC开始
- Java EE WEB工程师培训-JDBC+Servlet+JSP整合开发之03.JDBC Statement(1)
- Java EE WEB工程师培训-JDBC+Servlet+JSP整合开发之06.JDBC PreparedStatement
- Java EE WEB工程师培训-JDBC+Servlet+JSP整合开发之17.Session
- Java EE WEB工程师培训-JDBC+Servlet+JSP整合开发之34.Tomcat安装与配置 推荐
- Java EE WEB工程师培训-JDBC+Servlet+JSP整合开发之03.JDBC Statement(2) 推荐
- Java EE WEB工程师培训-JDBC+Servlet+JSP整合开发之09.JDBC DAO设计模式
- Java EE WEB工程师培训-JDBC+Servlet+JSP整合开发之10.Web_工程结构 推荐
- Java Web整合开发(12) -- JDBC
- JavaWeb物流管理项目开发(JSP、Servlet、JDBC):3、环境搭建