<%@ page contentType="text/html;charset=GBK"%>
<%@ page
import="java.util.*,java.sql.*,javax.sql.*,java.io.*,javax.naming.*"%>
<%
Connection connection = null;
Statement statement = null;
try{
//get connection
Class.forName("oracle.jdbc.driver.OracleDriver");
connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","***","***");
connection.setAutoCommit(false);
statement = connection.createStatement();
statement.execute("insert into aaa values(5)");
}catch(Exception e){
System.out.println("exception rollback");
Thread.sleep(10000);
System.out.println("-----");
//connection.rollback();
}finally{
Thread.sleep(10000);
System.out.println("-----");
statement.close();
connection.close();
}
%>
代码如上:
1. 执行过程发现在关闭连接之前提交的,这个跟各个数据库的实现不同;
虽然没有写提交代码,但oracle在关闭之前自动提交了
2.在过了10秒后,从plsql中监控发现,自动插入了5,但在10秒前数据库表中是没有插入5的。