Java学习者论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

手机号码,快捷登录

恭喜Java学习者论坛(https://www.javaxxz.com)已经为数万Java学习者服务超过8年了!积累会员资料超过10000G+
成为本站VIP会员,下载本站10000G+会员资源,购买链接:点击进入购买VIP会员
JAVA高级面试进阶视频教程Java架构师系统进阶VIP课程

分布式高可用全栈开发微服务教程

Go语言视频零基础入门到精通

Java架构师3期(课件+源码)

Java开发全终端实战租房项目视频教程

SpringBoot2.X入门到高级使用教程

大数据培训第六期全套视频教程

深度学习(CNN RNN GAN)算法原理

Java亿级流量电商系统视频教程

互联网架构师视频教程

年薪50万Spark2.0从入门到精通

年薪50万!人工智能学习路线教程

年薪50万!大数据从入门到精通学习路线年薪50万!机器学习入门到精通视频教程
仿小米商城类app和小程序视频教程深度学习数据分析基础到实战最新黑马javaEE2.1就业课程从 0到JVM实战高手教程 MySQL入门到精通教程
查看: 2634|回复: 0

{=是什么让DB2存储过程自動提交了DML操作 【

  [复制链接]

该用户从未签到

发表于 2011-11-2 09:29:01 | 显示全部楼层 |阅读模式
我用的DB2 ESE V9.7, Run 'db2ce', 运行以下代碼:

connect to sample @
create table s1.t1( id int)@
create procedure s1.p1
begin  
insert into s1.t1 values(1);
end @
call s12.p1 @
select id from s1.t1@

结果表中已经生成记录了。我已经将db2 command options 中的auto-commit 设置weioff了,是用db2set DB2OPTIONS=+c 的;考虑到工具De配置項ke能会有影响,已将命令窗口zhong的自動提交qu消,但还是會生成记录到表中,這是怎么回事? 请帮忙,谢谢。
欢迎来到Java学习者论壇,转载請注明地址:http://www.javaxxz.com.
回复

使用道具 举报

该用户从未签到

发表于 2011-11-2 09:29:24 | 显示全部楼层

Re:{=是什么让DB2存储过程自動提交了DML操作

call s1.p1 @
select id from s1.t1@

你这是在同一个SESSION中,当然可以看到自己insert的记录。 你应该打开另一个SESSION來檢查以确认事务是否提交。


建議参考一下事务的定义。
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2011-11-2 09:29:36 | 显示全部楼层

Re:{=是什么让DB2存储过程自動提交了DML操作

呵呵,在別的session看到的也是一样
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2011-11-2 09:29:47 | 显示全部楼层

Re:{=是什么让DB2存储过程自動提交了DML操作

DB2中沒有显式的事务開始语句,上一个事务的结束(Commit或Rollback)就是新事務的开始。

在命令行处理器中,默认的方式是自动提交(Auto Commit),所以執行一个语句之后就会隐含的自动执行Commit。如果想由程序员自行控制提交时機,可以把该参数设置为False,方法是:
update command option using c off

同一個事务中,即使没有提交插入,也是可以查看到数據的。如果不是同一个事务,那么插入操作提交以后才可以查询到。
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2011-11-2 09:29:59 | 显示全部楼层

Re:{=是什么让DB2存储过程自動提交了DML操作

LS请仔細看我問题:)
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2011-11-2 09:30:11 | 显示全部楼层

Re:{=是什么让DB2存储过程自動提交了DML操作

你用db2clp试试
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2011-11-2 09:30:35 | 显示全部楼层

Re:{=是什么让DB2存储过程自動提交了DML操作

谢谢,看起来存储过程的AUTOCOMMIT受调用它的环境的影响,DB2CMD,DB2CE,SQLJ,PHP等不同环境都会有默认设置的AUTOCOMMIT,而且看起来彼此不覆蓋
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2011-11-2 09:30:47 | 显示全部楼层

Re:{=是什么让DB2存储过程自動提交了DML操作

找到原因了?
回复 支持 反对

使用道具 举报

该用户从未签到

 楼主| 发表于 2011-11-2 09:30:59 | 显示全部楼层

Re:{=是什么让DB2存储过程自動提交了DML操作

It seems that DML cant be auto-committed in DB2 procedures even no 'commit' issued; from current tests, it properly  
be affected by diffrents caller environments such as CLP,Command Editor,SQLJ,PHP etc. For CLP and CE, they are in-
depend from their own setting options. See below labs:

Firstly, create relevent table and procedure in 'sample' database as follow via 'db2ce':

create table s1.t1( id int)@
create procedure s1.p1
begin  
insert into s1.t1 values(1);
end @

1. BehaviourS of auto-commit ON in CLP

1.1> Setting auto-commit ON in CLP, result as:

1.2> Query "s1.t1" table, no row existed, result as:

C:\\Documents and Settings\\Administrator>db2 select * from s1.t1

ID
-----------

  0 record(s) selected.


1.3> Call "s1.p1" procedure and query table again, result as:

C:\\Documents and Settings\\Administrator>db2 call s1.p1

  Return Status = 0

C:\\Documents and Settings\\Administrator>db2 select * from s1.t1

ID
-----------
  1

  1 record(s) selected.


1.4> Run another 'db2cmd', found 1 row inserted into table, same as step '1.3'.



2. BehaviourS of COMMIT via Command Editor calling procedure when CLP auto-commit is ON  

2.1> Run 'db2ce', click off 'Tools-> Tools Settings-> Command Editor -> Automatically commit SQL statements'.

2.2> Issue command of calling procedure and query table, results as:

------------------------------ Commands Entered ------------------------------
call s1.p1;
select * from s1.t1;
------------------------------------------------------------------------------
call s1.p1

  Return Status = 0

select * from s1.t1

ID   
-----------
  1
  1

  2 record(s) selected.

2.3> Switch to 'db2cmd', issue command 'db2 select * from s1.t1', no result returns, SQL command is waiting,
  result as:

C:\\Documents and Settings\\Administrator>db2 select * from s1.t1

- (flashing cursor)

2.4> Switch back to 'db2ce', issue 'commit;', execution successfully, result as:

------------------------------ Commands Entered ------------------------------
commit;
------------------------------------------------------------------------------
commit
DB20000I The SQL command completed successfully.

2.5> Switch to 'db2cmd', SQL finished successfully, the second row is inserted, result as:

C:\\Documents and Settings\\Administrator>db2 select * from s1.t1

ID
-----------
  1
  1

  2 record(s) selected.


2.6> Click on 'Tools-> Tools Settings-> Command Editor -> Automatically commit SQL statements' and call pro-
  cedure again 'call s1.p1;' in CE, then switch to 'db2ce', issuce command 'db2 select * from s1.t1', can
  see SQL command executed successfully with no waitting, result as:

C:\\Documents and Settings\\Administrator>db2 select * from s1.t1

ID
-----------
  1
  1
  1

  3 record(s) selected.


3. Behaviours when auto-commit OFF in CLP.

3.1> Setting auto-commit ON in CLP, result as:
3.2> Query current table rows, result as:

C:\\Documents and Settings\\Administrator>db2 select * from s1.t1

ID
-----------
  1
  1
  1

  3 record(s) selected.


3.3> Call procedure in CLP, then query the table in current session, result as:

C:\\Documents and Settings\\Administrator>db2 call s1.p1

  Return Status = 0

C:\\Documents and Settings\\Administrator>db2 select * from s1.t1

ID
-----------
  1
  1
  1
  1

  4 record(s) selected.


3.4> Run another 'db2cmd', issue command 'db2 select * from s1.t1', SQL command excecute waitting,
  no any return; switch back to the first 'db2cmd' and issue command 'db2 rollback', executed  
  successfully and the second 'db2mcd' SQL finished successfully with rows return, resutl as:

C:\\Documents and Settings\\Administrator>db2 select * from s1.t1

ID
-----------
  1
  1
  1

  3 record(s) selected.


4. BehaviourS of COMMIT via Command Editor calling procedure when CLP auto-commit is OFF

4.1> Run 'db2ce', click on 'Tools-> Tools Settings-> Command Editor -> Automatically commit SQL statements'.

4.2> In 'db2ce', call procedure, executed successfully, resutl as:

------------------------------ Commands Entered ------------------------------
call s1.p1;
------------------------------------------------------------------------------
call s1.p1

  Return Status = 0

4.3> Switch to 'db2cmd', query table rows, executed successfully without waiting, result as:

C:\\Documents and Settings\\Administrator>db2 select * from s1.t1

ID
-----------
  1
  1
  1
  1

  4 record(s) selected.

4.4> click off 'Tools-> Tools Settings-> Command Editor -> Automatically commit SQL statements', and call  
  procedure again, then switch to 'db2cmd' and query table rows, it waits, result as:

C:\\Documents and Settings\\Administrator>db2 select * from s1.t1


4.5> Issue command 'commit' in 'db2ce' window, it executed successfully; switch to 'db2cmd', the waitting  
  SQL finished successfully, result as:

C:\\Documents and Settings\\Administrator>db2 select * from s1.t1

ID
-----------
  1
  1
  1
  1
  1

  5 record(s) selected.
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2011-11-2 09:31:15 | 显示全部楼层

Re:{=是什么让DB2存储过程自動提交了DML操作

多個作用域之间的一個很有趣的問题 ,值得关注一下
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|Java学习者论坛 ( 声明:本站资料整理自互联网,用于Java学习者交流学习使用,对资料版权不负任何法律责任,若有侵权请及时联系客服屏蔽删除 )

GMT+8, 2024-5-22 04:38 , Processed in 0.423643 second(s), 45 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表