JAVA WEB
来源:互联网 发布:知豆汽车怎么样 编辑:程序博客网 时间:2024/06/03 16:54
###1.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 -pEnter password: ****Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 314Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.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 changedmysql> 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: 0mysql> update account set money = money +1000 where name = 'jack';Query OK, 1 row affected (0.01 sec)Rows matched: 1 Changed: 1 Warnings: 0mysql> 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: 0mysql> 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: 0mysql> 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: 0mysql> update account set money = money + 2000 where name = 'jack';Query OK, 1 row affected (0.00 sec)Rows matched: 1 Changed: 1 Warnings: 0mysql> commit;Query OK, 0 rows affected (0.01 sec)mysql>
*
阅读全文
0 0
- WEB和JAVA WEB
- JAVA WEB
- java web
- JAVA WEB
- java web
- java web
- Java web
- JAVA WEB
- java Web
- Java web
- Java web
- Java Web
- Java Web
- java web
- java web
- java web
- java web
- java web
- DBI接口与DPI接口与DSI接口
- 在Eclipse中安装python插件的方法
- python中raw字符串与多行字符串
- 【一图看懂】机器学习6大算法,优势劣势全解析
- 直方图
- JAVA WEB
- Oracle 用户账号解锁、密码重置、设置密码永不过期
- Android与Java语法的差异?
- 关于Super
- Spring 注解 定时器
- 对a*算法的探索
- 今日小程序推荐:诀配有质感的生活体验
- Acunetix Web Vulnerability Scanner10 破解包、安装及简易教程文档视频大全
- 我的第一篇博客