首页 | 互联网 | IT动态 | IT培训 | Cisco | Windows | Linux | Java | .Net | Oracle | 软件测试 | C/C++ | 嵌入式开发 | 存储世界 | 服务器
网络设备 | IDC | 安全 | 求职招聘 | 数字网校 | 网页设计 | 平面设计 | 技术专题 | 电子书下载 | 教学视频 | 源码下载 | 搜索 | 博客 | 论坛
中国IT实验室Linux频道
中国IT教育
Google
首页 资讯动态 认证考试 新手入门 核心技术 高级技术 J2EE J2ME Java&XML 开源技术 其他技术 RSS订阅 论坛 专题
您现在的位置: 中国IT实验室 >> Java >> J2EE >> JDBC/JDO >> 正文

oracle 事务隔离级别,用jdbc体验

    以上 2 点都会保证不能脏读脏写,就是说不能得到另外一个事务修改没有提交的事务的修改后的数据。

 

用一个例子来解释一下

BaseTestCase

package test.transaction;

 

import java.sql.Connection;

import java.sql.DriverManager;

 

import junit.framework.TestCase;

 

public class BaseTestCase extends TestCase {

       protected Connection conn = null;

 

       private String user = null;

 

       private String pwd = null;

 

       private String url = null;

 

       /**

        * override super setup...

        */

       protected void setUp() throws Exception {

              super.setUp();

              try {

                     Class.forName("oracle.jdbc.driver.OracleDriver");

              } catch (ClassNotFoundException e) {

                     e.printStackTrace();

              }

              url = "jdbc:oracle:thin:@10.200.10.19:1521:aaaa";

              user = "loocky";

              pwd = "loocky";

              try {

                     conn = DriverManager.getConnection(url, user, pwd);

 

              } catch (Exception e) {

                     e.printStackTrace();

 

              }

 

       }

protected void tearDown() throws Exception {

              super.tearDown();

              try{

                     if(conn!=null){

                            if(!conn.isClosed()){

                                   conn.close();

                            }

                     }

              }catch(Exception e){

                     e.printStackTrace();

              }finally{

                     if(!conn.isClosed()){

                            conn.close();

                     }

              }

       }

}

             

             

TestTransaction0

 

package test.transaction;

 

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

 

public class TestTransaction0 extends BaseTestCase {

 

       protected void setUp() throws Exception {

             

              super.setUp();

       }

 

       protected void tearDown() throws Exception {

      

              super.tearDown();

       }

       public void test0() {

              try {

                     System.out.println(this.getClass().getName());

                     conn.setAutoCommit(false);

                     conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);

                     String sql1="update sys_dbinfo  set item='bbb' where id =1" ;

                     PreparedStatement  ps1= conn.prepareStatement(sql1);

                    

                     ps1.executeUpdate();

                     ps1.close();

                    

                     String sql2 ="select item from sys_dbinfo where id =1";

                    

                     PreparedStatement  ps2= conn.prepareStatement(sql2);

                     ResultSet rs2 = ps2.executeQuery();

                     rs2.next();

                     System.out.println(rs2.getString(1));

                     rs2.close();

                    

                     ps2.close();

                     conn.commit();

                     System.out.println(this.getClass().getName());

              } catch (Exception e) {

                     e.printStackTrace();

              }

 

       }

 

 

}

上一页  [1] [2] [3] 下一页

【责编:Youping】

中国IT教育

相关产品和培训
文章评论
 友情推荐链接
 认证培训
 专题推荐

 ·关于Java框架技术专题
 ·XML全攻略技术专题
 ·JAVA开源技术介绍专题
 ·Java嵌入式开发之J2ME技术专题
 ·超前体验 Oracle 11g的5个新特性…
 ·揭密使用VB.NET的五个实用技巧
 ·Oracle和SQL Server常用函数对比专题…
 ·展现C#世界 C#程序设计专题…
 ·Java入门 Tomcat的配置技巧精华专题…
 ·Oracle RMAN物理备份技术详解…
 今日更新
 社区讨论
 博客论点
 频道精选
 Java 频道导航