Hi.
 
I use the following code to insert a new record in the database.
mDataSource is an instance of GenericDataSource, configured in struts-config.xml
 
 
    Connection conn = null;
   
    try {
        conn = mDataSource.getConnection();
        Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                                              ResultSet.CONCUR_UPDATABLE);
       
        ResultSet uprs = stmt.executeQuery("SELECT * FROM Users");
        uprs.moveToInsertRow();
   
        uprs.updateObject( "FullName", "xxx" );
        uprs.updateObject( "Password", "yyy" );
        uprs.updateObject( "Email",    "[EMAIL PROTECTED]" );
   
        uprs.insertRow();
        uprs.moveToCurrentRow();
   
        stmt.close();
    } catch (SQLException sqle) {
        throw new CoreException("CoreException while updating user : " +
                                 sqle.getMessage());
    } finally {
        try {
            conn.close();
        } catch (SQLException sqle) {
        }
    }
   
   
Everything passes ok, but nothing is written in the database.
I looked at the source of GenericDataSource and GenericConnection and found the following:
 
GenericConnection.close() method calls conn.rollback() before closing the connection, no matter what is the value of autoCommit flag.
Probably this is a normal behaviour when you use DataSource, configured to autoCommit=false, or if some exception occured. But my DataSource is autoCommit=true and no exceptions occured.
 
My question is: Should I always call conn.commit() after performing my database operations, or there is a bug in the implementation of GenericConnection.
 

Regards,
Danail Grigorov

Reply via email to