日期:2014-05-17  浏览次数:20786 次

问什么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
        {
&n