The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.sql  [73 examples] > Connections  [10 examples]

e240. Committing and Rolling Back Updates to a Database

By default, a connection commits all updates to the database immediately and automatically. For example, executing an UPDATE SQL query immediately commits the change. This example shows how to disable auto-commits and explicitly commit.
    try {
        // Disable auto commit
        connection.setAutoCommit(false);
    
        // Do SQL updates...
    
        // Commit updates
        connection.commit();
    } catch (SQLException e) {
        // Rollback update
        connection.rollback();
    }

 Related Examples
e235. Connecting to an Oracle Database
e236. Connecting to a MySQL Database
e237. Connecting to a SQLServer Database
e238. Listing All Available Parameters for Creating a JDBC Connection
e239. Determining If a Database Supports Transactions
e241. Handling a SQL Exception
e242. Determining If a SQL Warning Occurred
e243. Getting the Driver of a Connection
e244. Setting the Number of Rows to Prefetch When Executing a SQL Query

See also: Batching    Database Meta Data    Deleting Data    Drivers    Importing and Exporting    Inserting and Updating Data    Oracle OBJECTs    Oracle VARRAYs    Procedures and Functions    Retrieving Data    Scrollable Result Sets    Tables    Updatable Result Sets   


© 2002 Addison-Wesley.