Releases SQL Database resources. - Android Database

Android examples for Database:Database Connection

Description

Releases SQL Database resources.

Demo Code


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

import java.sql.PreparedStatement;

import java.sql.SQLException;

public class Main {
    /**/*from www .  j  a  va  2s  .  c o m*/
     * Releases SQL resources. It's best to release SQL resources in reverse
     * order of their creation. This method <strong>must be used</strong> when
     * dealing with SQL stuff.
     * https://dev.mysql.com/doc/refman/5.0/en/connector-j-usagenotes-statements.html#connector-j-examples-execute-select
     * 
     * @parameter sqlConnection
     * A SQL Connection object. It's okay if this object is null or if it was
     * never given an actual connection to a SQL database.
     * 
     * @parameter sqlStatement
     * A SQL PreparedStatement object. It's okay if this object is null or if
     * it was never given an actual SQL statement / query to run.
     */
    public static void closeSQL(final Connection sqlConnection,
            final PreparedStatement sqlStatement) {
        closeSQLStatement(sqlStatement);
        closeSQLConnection(sqlConnection);
    }

    /**
     * Releases a SQL PreparedStatement resource.
     * 
     * @parameter sqlStatement
     * A SQL PreparedStatement object. It's okay if this object is null or if
     * it was never given an actual SQL statement / query to run.
     */
    public static void closeSQLStatement(
            final PreparedStatement sqlStatement) {
        if (sqlStatement != null) {
            try {
                sqlStatement.close();
            } catch (final SQLException e) {

            }
        }
    }

    /**
     * Releases a SQL Connection resource.
     * 
     * @parameter sqlConnection
     * A SQL Connection object. It's okay if this object is null or if it was
     * never given an actual connection to a SQL database.
     */
    public static void closeSQLConnection(final Connection sqlConnection) {
        if (sqlConnection != null) {
            try {
                sqlConnection.close();
            } catch (final SQLException e) {

            }
        }
    }
}

Related Tutorials