oracle 改变autocommit,问什么setAutoCommit没有作用解决方法

当前位置:我的异常网» Oracle管理 » 问什么setAutoCommit没有作用解决方法

问什么setAutoCommit没有作用解决方法

www.myexceptions.net  网友分享于:2013-03-02  浏览:66次

问什么setAutoCommit没有作用

关键代码:

stmt   =   conn.createStatement();

conn.setAutoCommit(false);/*注意这里,下面没有使用conn.commit()*/

stmt.addBatch( "insert   into   t_one   values(   6,   'eee '   ) ");

stmt.addBatch( "insert   into   t_one   values(   7,   'eee '   ) ");

stmt.addBatch( "insert   into   t_one   values(   8,   'eee '   ) ");

stmt.addBatch( "insert   into   t_one   values(   9,   'eee '   ) ");

stmt.executeBatch();

在没有使用conn.commit()的情况下,为什么执行完这些语句数据还是会加入表?

也就是说在执行完上面语句后能够通过其他用户登陆数据库查到这些数据

完全代码

import   java.sql.*;

public   class   TestDML

{

public   static   void   main(String[]   args)   throws   ClassNotFoundException   ,   SQLException   ,   Exception

{

Connection   conn   =   null;

Statement   stmt   =   null;

try

{

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

//注册Oracle

conn   =   DriverManager.getConnection(   "jdbc:oracle:thin:@127.0.0.1:1521:NODB "   ,   "bbs "   ,   "bbs "   );

//得到Oracle的连接

stmt=conn.createStatement();

conn.setAutoCommit(false);

stmt.addBatch( "{call   p(6, 'eee ')} ");

stmt.addBatch( "{call   p(7, 'eee ')} ");

stmt.addBatch( "{call   p(8, 'eee ')} ");

stmt.addBatch( "{call   p(9, 'eee ')} ");

stmt.executeBatch();

}

catch(ClassNotFoundException   e)

{

e.printStackTrace();

}

catch(SQLException   e)

{

e.printStackTrace();

}

catch(Exception   e)

{

e.printStackTrace();

}

finally

{

try

{//将打开的东西关掉:如

文章评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值