Java Utililty Methods JDBC Connection Close

List of utility methods to do JDBC Connection Close

Description

The list of methods to do JDBC Connection Close are organized into topic(s).

Method

voidclose(Connection connection)

Closes the sql connection.

if (connection != null) {
    try {
        connection.close();
    } catch (SQLException e) {
voidclose(Connection rs)
close
rs.close();
voidclose(Object obj)
close
if (obj instanceof ResultSet) {
    try {
        ((ResultSet) obj).close();
    } catch (Exception e) {
if (obj instanceof PreparedStatement) {
    try {
...
voidcloseConnection(Closeable... closes)
close Connection
for (Closeable close : closes) {
    try {
        if (close != null) {
            close.close();
    } catch (IOException e) {
        e.printStackTrace();
voidcloseIfNotNull(Connection conn)
close If Not Null
if (conn == null) {
    return;
try {
    conn.close();
} catch (SQLException e) {
    e.printStackTrace();
voidcloseJDBC(Object obj)
Utility method to safety close various jdbc objects ResultSet, Statement, PreparedStatement
if (obj == null)
    return;
try {
    if (obj instanceof ResultSet)
        ((ResultSet) obj).close();
    if (obj instanceof Statement)
        ((Statement) obj).close();
    if (obj instanceof PreparedStatement)
...
voidClosePhase(long phaseId, Connection con)
This method set status to close of specified phase.
executeStatement(con, "UPDATE project_phase SET phase_status_id = 3 WHERE project_phase_id = " + phaseId);
voidcloseQuietly(MongoClient mongoClient)
close Quietly
mongoClient.close();
voidcloseResources(Object[] resources)
close Resources
for (Object resource : resources) {
    if (resource != null) {
        try {
            if (resource instanceof HttpURLConnection) {
                ((HttpURLConnection) resource).disconnect();
            } else if (resource instanceof Closeable) {
                ((Closeable) resource).close();
            } else if (resource instanceof Connection) {
...
voidcloseSilently(@WillClose Connection c)
close Silently
try {
    if (c != null) {
        c.close();
} catch (SQLException e) {
    assert true;