commit Database Connection - Java java.sql

Java examples for java.sql:Connection

Description

commit Database Connection

Demo Code


//package com.java2s;
import java.sql.Connection;

import java.sql.SQLException;

public class Main {
    public static boolean commit(Connection conn, boolean oldCommitStatus) {
        if (conn == null) {
            return true;
        }//from w  w w .  j  a v a 2 s .co m
        try {
            conn.commit();
            conn.setAutoCommit(oldCommitStatus);
            return true;
        } catch (SQLException e1) {
            e1.printStackTrace();
            return false;
        }
    }

    public static Boolean setAutoCommit(Connection conn,
            boolean commitStatus) {
        if (conn == null) {
            return true;
        }
        try {
            boolean commit = conn.getAutoCommit();
            conn.setAutoCommit(commitStatus);
            return commit;
        } catch (SQLException e1) {
            e1.printStackTrace();
            return true;
        }
    }
}

Related Tutorials