All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.avaje.dbmigration.util.JdbcClose Maven / Gradle / Ivy

There is a newer version: 1.3.2
Show newest version
package org.avaje.dbmigration.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Utility for closing raw Jdbc resources.
 */
public class JdbcClose {

  private static final Logger logger = LoggerFactory.getLogger(JdbcClose.class);

  /**
   * Close the connection logging if an error occurs.
   */
  public static void close(Connection connection) {
    try {
      connection.close();
    } catch (SQLException e) {
      logger.warn("Error closing connection", e);
    }
  }

  /**
   * Rollback the connection logging if an error occurs.
   */
  public static void rollback(Connection connection) {
    try {
      connection.rollback();
    } catch (SQLException e) {
      logger.warn("Error on connection rollback", e);
    }
  }

  public static void close(PreparedStatement query) {
    try {
      query.close();
    } catch (SQLException e) {
      logger.warn("Error closing PreparedStatement", e);
    }
  }

  public static void close(ResultSet resultSet) {
    try {
      resultSet.close();
    } catch (SQLException e) {
      logger.warn("Error closing resultSet", e);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy