体验oracle中的con.commit()
2005-07-26 20:53
169 查看
新建一个class
package cn.com.cnpc.tz.tetd.workflow;
import java.sql.*;
import cn.com.cnpc.tz.tetd.common.Notes;
import java.sql.Connection;
public class test
{
public test()
{
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void main(String args[]) {
Connection con = null;
try {
Class.forName(Notes.DRIVER_NAME); //装载驱动程序
con = DriverManager.getConnection(Notes.DB_URL,
"tetdmis", "tetdmis"); //获得数据库连接对象
con.setAutoCommit(false);
String str = "insert into tetdmis.imagetable values(1,2,null)";
Statement stmt = con.createStatement();
int d = stmt.executeUpdate(str);
System.out.println("插入了" + d + "条");
ResultSet rs = stmt.executeQuery("select * from imagetable");
while(rs.next())
{
System.out.println("====================");
}
con.commit();
String str1 = "insert into tetdmis.imagetable values(3,4,null)";
stmt.executeUpdate(str1);
String dd = null;
if (dd.equals(""))
{
System.out.println("11111111111111111111111111");
}
con.commit();
} catch (Exception e) {
e.printStackTrace();
try
{
con.rollback();
}catch(Exception ex)
{
ex.printStackTrace();
}
}
}
private void jbInit() throws Exception {
}
}
------------------------------------------------------------------------
后台打印出的:
java.lang.NullPointerException
at cn.com.cnpc.tz.tetd.workflow.test.main(test.java:38)
插入了1条
====================
分析:异常出现在
if (dd.equals(""))
{
System.out.println("11111111111111111111111111");
}
一旦这里出现异常,它下面的con.commit()就不会执行,然后,最外面的catch就会con.rollback()
这样第二次插入的东西就没有插入进去
-----------------------------------------------------------------------------------------------------
怎样理解catch与exception
method()
{
try{
try{JJ1();}catch(Exception e1){throw e1;//抛向最外面}
try{JJ2();}catch(Exception e2){throw e2;//抛向最外面}
try{JJ3();}catch(Exception e3){throw e3;//抛向最外面}
}catch(Exception e)
{ e.print(); thow e; //将会交给Exception }
}
package cn.com.cnpc.tz.tetd.workflow;
import java.sql.*;
import cn.com.cnpc.tz.tetd.common.Notes;
import java.sql.Connection;
public class test
{
public test()
{
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void main(String args[]) {
Connection con = null;
try {
Class.forName(Notes.DRIVER_NAME); //装载驱动程序
con = DriverManager.getConnection(Notes.DB_URL,
"tetdmis", "tetdmis"); //获得数据库连接对象
con.setAutoCommit(false);
String str = "insert into tetdmis.imagetable values(1,2,null)";
Statement stmt = con.createStatement();
int d = stmt.executeUpdate(str);
System.out.println("插入了" + d + "条");
ResultSet rs = stmt.executeQuery("select * from imagetable");
while(rs.next())
{
System.out.println("====================");
}
con.commit();
String str1 = "insert into tetdmis.imagetable values(3,4,null)";
stmt.executeUpdate(str1);
String dd = null;
if (dd.equals(""))
{
System.out.println("11111111111111111111111111");
}
con.commit();
} catch (Exception e) {
e.printStackTrace();
try
{
con.rollback();
}catch(Exception ex)
{
ex.printStackTrace();
}
}
}
private void jbInit() throws Exception {
}
}
------------------------------------------------------------------------
后台打印出的:
java.lang.NullPointerException
at cn.com.cnpc.tz.tetd.workflow.test.main(test.java:38)
插入了1条
====================
分析:异常出现在
if (dd.equals(""))
{
System.out.println("11111111111111111111111111");
}
一旦这里出现异常,它下面的con.commit()就不会执行,然后,最外面的catch就会con.rollback()
这样第二次插入的东西就没有插入进去
-----------------------------------------------------------------------------------------------------
怎样理解catch与exception
method()
{
try{
try{JJ1();}catch(Exception e1){throw e1;//抛向最外面}
try{JJ2();}catch(Exception e2){throw e2;//抛向最外面}
try{JJ3();}catch(Exception e3){throw e3;//抛向最外面}
}catch(Exception e)
{ e.print(); thow e; //将会交给Exception }
}
相关文章推荐
- oracle中的隐式提交(auto commit)
- 执行commit时oracle做哪些工作
- 【Oracle】-【COMMIT对索引的影响】-从trace看COMMIT对索引的影响
- Oracle Block scn/commit scn/cleanout scn 说明
- ORACLE COMMIT以及ROLLBACK机制
- oracle commit后怎样恢复被修改的数据
- 执行COMMIT时ORACLE要做那些工作
- 【Oracle】-【隐式commit】-正常与异常退出对commit的作用
- oracle 中的commit的操作
- Oracle 初体验
- Oracle教程之Oracle Commit
- oracle的commit操作
- oracle commit的时候发生了什么
- commit提交,数据库做了什么-oracle
- 关于Oracle误操作--数据被Commit后的数据回退恢复(闪回)
- oracle基于COMMIT SCN的物化视图日志如何支持快速刷新(一)
- Oracle redo undo commit rollback剖析
- oracle 事务处理 commit rollback
- oracle笔记整理3——commit,rollback,flashback
- oracle:commit,rollback,savepoint