- 浏览: 952212 次
文章分类
- 全部博客 (428)
- Hadoop (2)
- HBase (1)
- ELK (1)
- ActiveMQ (13)
- Kafka (5)
- Redis (14)
- Dubbo (1)
- Memcached (5)
- Netty (56)
- Mina (34)
- NIO (51)
- JUC (53)
- Spring (13)
- Mybatis (17)
- MySQL (21)
- JDBC (12)
- C3P0 (5)
- Tomcat (13)
- SLF4J-log4j (9)
- P6Spy (4)
- Quartz (12)
- Zabbix (7)
- JAVA (9)
- Linux (15)
- HTML (9)
- Lucene (0)
- JS (2)
- WebService (1)
- Maven (4)
- Oracle&MSSQL (14)
- iText (11)
- Development Tools (8)
- UTILS (4)
- LIFE (8)
最新评论
-
Donald_Draper:
Donald_Draper 写道刘落落cici 写道能给我发一 ...
DatagramChannelImpl 解析三(多播) -
Donald_Draper:
刘落落cici 写道能给我发一份这个类的源码吗Datagram ...
DatagramChannelImpl 解析三(多播) -
lyfyouyun:
请问楼主,执行消息发送的时候,报错:Transport sch ...
ActiveMQ连接工厂、连接详解 -
ezlhq:
关于 PollArrayWrapper 状态含义猜测:参考 S ...
WindowsSelectorImpl解析一(FdMap,PollArrayWrapper) -
flyfeifei66:
打算使用xmemcache作为memcache的客户端,由于x ...
Memcached分布式客户端(Xmemcached)
事务基础知识:http://my.oschina.net/jeffli1993/blog/684762
数据库事务隔离级别-- 脏读、幻读、不可重复读(清晰解释) :http://blog.csdn.net/jiesa/article/details/51317164
1.测试类
2.控制台输出如下:
==========currentThread:file:/F:/Myeclipse/test/WebRoot/WEB-INF/classes/
==========File:/F:/Myeclipse/test/WebRoot/WEB-INF/classes/com/test/controller/test/
==========Path:/F:/Myeclipse/test/WebRoot/WEB-INF/classes/com/test/controller/test/
======isSupportsTransactions:true
======isSupportLevel:true
======DefaultTransactionIsolation:2
3.从上可以看出Mysql默认支持的事物为:
/**
* A constant indicating that
* dirty reads are prevented; non-repeatable reads and phantom
* reads can occur. This level only prohibits a transaction
* from reading a row with uncommitted changes in it.
*/
int TRANSACTION_READ_COMMITTED = 2;
可以避免脏数据的发生,但不重读,幻读可能发生。
4.从Connection的源码中,我们可以看到事务等级的定义如下:
数据库事务隔离级别-- 脏读、幻读、不可重复读(清晰解释) :http://blog.csdn.net/jiesa/article/details/51317164
1.测试类
public class TestMySQL { public static void main(String[] args) { String path = Thread.currentThread().getContextClassLoader ().getResource("").toString(); System.out.println("==========currentThread:"+path); TestMySQL tm = new TestMySQL(); System.out.println("==========File:"+tm.getClass().getResource("").getFile()); System.out.println("==========Path:"+tm.getClass().getResource("").getPath()); String jdbcPath = tm.getClass().getResource("").getPath(); try { File pFile = new File(jdbcPath+"jdbc.properties"); FileInputStream pInStream=null; try { pInStream = new FileInputStream(pFile ); } catch (FileNotFoundException e) { e.printStackTrace(); } Properties pInfo = new Properties(); try { pInfo.load(pInStream ); } catch (IOException e) { e.printStackTrace(); } String drive = pInfo.getProperty("driver"); String url = pInfo.getProperty("url"); String user = pInfo.getProperty("user"); String pwd = pInfo.getProperty("pwd"); Class.forName(drive); Connection conn = DriverManager.getConnection(url, user, pwd); DatabaseMetaData metaData = conn.getMetaData(); // 是否支持的事务 boolean isSupport = metaData.supportsTransactions(); System.out.println("======isSupportsTransactions:"+isSupport); // 是否支持的Connection.TRANSACTION_SERIALIZABLE等级事务 boolean isSupportLevel = metaData .supportsTransactionIsolationLevel(Connection.TRANSACTION_SERIALIZABLE); System.out.println("======isSupportLevel:"+isSupportLevel); // 获取默认事务 int defaultIsolation = metaData.getDefaultTransactionIsolation(); System.out.println("======DefaultTransactionIsolation:"+defaultIsolation); if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } } }
2.控制台输出如下:
==========currentThread:file:/F:/Myeclipse/test/WebRoot/WEB-INF/classes/
==========File:/F:/Myeclipse/test/WebRoot/WEB-INF/classes/com/test/controller/test/
==========Path:/F:/Myeclipse/test/WebRoot/WEB-INF/classes/com/test/controller/test/
======isSupportsTransactions:true
======isSupportLevel:true
======DefaultTransactionIsolation:2
3.从上可以看出Mysql默认支持的事物为:
/**
* A constant indicating that
* dirty reads are prevented; non-repeatable reads and phantom
* reads can occur. This level only prohibits a transaction
* from reading a row with uncommitted changes in it.
*/
int TRANSACTION_READ_COMMITTED = 2;
可以避免脏数据的发生,但不重读,幻读可能发生。
4.从Connection的源码中,我们可以看到事务等级的定义如下:
/** 不支持事务 * A constant indicating that transactions are not supported. */ int TRANSACTION_NONE = 0; /**支持事务,脏数据,不重读,幻读可能发生。 * A constant indicating that * dirty reads, non-repeatable reads and phantom reads can occur. * This level allows a row changed by one transaction to be read * by another transaction before any changes in that row have been * committed (a "dirty read"). If any of the changes are rolled back, * the second transaction will have retrieved an invalid row. */ int TRANSACTION_READ_UNCOMMITTED = 1; /**支持事务,不重读,幻读可能发生。 * A constant indicating that * dirty reads are prevented; non-repeatable reads and phantom * reads can occur. This level only prohibits a transaction * from reading a row with uncommitted changes in it. */ int TRANSACTION_READ_COMMITTED = 2; /**支持事务,幻读可能发生。 * A constant indicating that * dirty reads and non-repeatable reads are prevented; phantom * reads can occur. This level prohibits a transaction from * reading a row with uncommitted changes in it, and it also * prohibits the situation where one transaction reads a row, * a second transaction alters the row, and the first transaction * rereads the row, getting different values the second time * (a "non-repeatable read"). */ int TRANSACTION_REPEATABLE_READ = 4; /**支持事务,脏数据,不重读,幻读不可能发生。 * A constant indicating that * dirty reads, non-repeatable reads and phantom reads are prevented. * This level includes the prohibitions in * <code>TRANSACTION_REPEATABLE_READ</code> and further prohibits the * situation where one transaction reads all rows that satisfy * a <code>WHERE</code> condition, a second transaction inserts a row that * satisfies that <code>WHERE</code> condition, and the first transaction * rereads for the same condition, retrieving the additional * "phantom" row in the second read. */ int TRANSACTION_SERIALIZABLE = 8;
发表评论
-
Deadlock found when trying to get lock; try restarting transaction解决方式
2017-07-18 23:00 1963MySQL 事务的学习整理:http://blog.csdn. ... -
MySQL慢日志
2017-05-18 16:05 993The Slow Query Log:https://dev. ... -
The table is full问题解决过程
2017-05-06 15:29 7272The table‘xxxx’is full 设置临时表大小 ... -
百万级数据-程序迁移后续
2017-04-13 18:09 1584百万级数据-程序迁移:http://donald-draper ... -
Msyql日期字符串转换
2017-04-01 14:13 497Date和String的互相转换:http://www.tui ... -
Mysql添加约束
2017-03-31 16:28 858MySQL中对三种约束的支持:http://leekai.me ... -
Mysql FEDERATED引擎
2016-11-29 15:51 568使用mysql federated引擎构建MySQL分布式数据 ... -
MySQL触发器
2016-11-24 19:04 672CHANGE MASTER:http://dev.mysql. ... -
Mysql主从配置
2016-11-11 18:31 4841、主从服务器分别作以下操作: 1)版本一致 2)初始 ... -
百万级数据-程序迁移
2016-09-29 19:03 2570JVM学习笔记:http://blog.csdn.net/cu ... -
Mysql 备份工具XtraBackup增量备份
2016-08-05 18:11 683安装:http://donald-draper.iteye.c ... -
Mysql 备份工具XtraBackup全量备份
2016-08-05 16:41 521Percona安装:http://donald-draper. ... -
Mysql 备份工具XtraBackup 安装
2016-08-05 16:28 903开源热备工具XtraBackup下载:https://www. ... -
sysbench基准测试
2016-08-01 17:45 722下载sysbench:http://dev.mysql.com ... -
mysql 事务处理
2016-07-29 16:07 478创建表: CREATE TABLE `role` ( ` ... -
mysql 全文索引
2016-07-28 11:03 574mysql大表查询的时候,'String%'模糊查询可以使用B ... -
MySQL 物理文件的迁移
2016-07-26 15:39 2280参考资料:http://www.cnblogs.com/adv ... -
centos7 安装mysql
2016-07-26 11:36 707下载MYSQL-RPM包:http://downloads.m ... -
mysql 大表添加索引注意事项
2016-07-25 16:01 2583LINXU top命令: http://www.c ... -
mysql 大表分页查询测试分析优化
2016-07-25 11:30 1463索引概念: http://blog.csdn.net/xlur ...
相关推荐
mysql事务处理的意义 事务处理机制在程序开发过程中有着非常重要的作用,它可以使整个系统更加安全,例如在银行处理转账业务时,如果A账户中的金额刚被发出,而B账户还没来得及接收就发生停电,这会给银行和个人带来...
MySQL事务隔离级别详解,这个面试经常会面到,必会呀,哈哈
02.MySQL事务篇.pdf02.MySQL事务篇.pdf02.MySQL事务篇.pdf02.MySQL事务篇.pdf02.MySQL事务篇.pdf02.MySQL事务篇.pdf02.MySQL事务篇.pdf02.MySQL事务篇.pdf02.MySQL事务篇.pdf02.MySQL事务篇.pdf02.MySQL事务篇.pdf02...
Mysql事务的基本使用-基本原理及特点ACID
Mysql事务以及锁原理讲解,方便大家了解mysql事务和锁的原理
mysql事务处理用法与实例详解
jdbc+spring+mysql事务理解和分析
关于mysql的事务处理 public static void StartTransaction(Connection con, String[] sqls) throws Exception { if (sqls == null) { return; } Statement sm = null; try { // 事务开始 System....
关于mysql事务的学习,包含一个一个PPT讲解,以及相应的几个案例源码。
超高并发下如何对Mysql事务进行优化
06-VIP-深入理解Mysql事务隔离级别与锁机制.pdf
一、数据库索引概述; 二、数据库索引分类; 三、Mysql数据库管理索引; 四、数据库事务概述; 五、数据库事务特性; 六、Mysqk数据库管理事务;
这份PDF文档《MySQL事务(五).pdf》是关于MySQL数据库事务管理的深入指南,作为系列教程的第五部分,它详尽地介绍了事务处理的概念、原则以及在实际数据库操作中的应用。内容包括: 事务基础:解释事务的概念和...
nodejs + mysql 事物处理问题 呵呵 看了就知道 记得npm install啊 需要的东西啊 本想免费 苦于没积分 ,需要的的同学,给点分吧
事务就是一组原子性的SQL查询,或者说一个独立的工作单元。如果数据库引擎能够成功的对数据库应用该组查询的全部语句,那么执行该组查询。如果其中有任何一条语句因为崩溃或其他原因无法执行,那么所有的语句都不会...
mysql 事务等待锁超时分析
关于mysql 事务管理的介绍,说明mysql事务操作的
NULL 博文链接:https://cuishuangjia.iteye.com/blog/964885
MySQL学习笔记:MySQL安装,MySQL数据类型,MySQL事务,MySQL函数等学习笔记整理
主要介绍了Java实现的mysql事务处理操作,结合实例形式较为详细的分析了Java基于JDBC操作mysql数据库实现事务处理的相关概念、操作技巧与注意事项,需要的朋友可以参考下