Class SQLUtils

java.lang.Object
ru.bgcrm.util.sql.SQLUtils

public class SQLUtils extends Object
  • Field Details

  • Constructor Details

    • SQLUtils

      public SQLUtils()
  • Method Details

    • closeConnection

      public static final void closeConnection(Connection con)
      Safe closing of DB connection if it isn't null and not closed already. Faster comparing to closeConnection(Connection...), doesn't create arrays on every call.
      Parameters:
      con - connection, null safe
    • closeConnection

      public static final void closeConnection(Connection... con)
      Safe closing of DB connections if each of them isn't null and not closed already
      Parameters:
      con - connections
    • getConnectionId

      public static int getConnectionId(Connection connection) throws SQLException
      Throws:
      SQLException
    • lastInsertId

      public static int lastInsertId(PreparedStatement ps) throws SQLException
      Throws:
      SQLException
    • tableExists

      public static boolean tableExists(Connection con, String tableName)
      Checks whether a table exists in the DB
      Parameters:
      con - the DB connection
      tableName - the checked table name
      Returns:
      true if the table exists, false if it doesn't exist or the DB is not accessible
    • columnExist

      public static boolean columnExist(Connection con, String table, String column)
    • commitConnection

      public static final void commitConnection(Connection con)
      Commits a single DB connection
      Parameters:
      con - the connection
    • setAutoCommit

      public static final void setAutoCommit(Connection connection)
      Sets automatic commit (autocommit) for the given connection
      Parameters:
      connection - the connection
    • javaDateFormatToSql

      public static final String javaDateFormatToSql(String format)
      Converts a SimpleDateFormat-style date format to the format for the MySQL DATE_FORMAT function
      Parameters:
      format - the input format
      Returns:
      the converted format
    • getTableColumns

      public Set<String> getTableColumns(Connection con, String tableName) throws SQLException
      Throws:
      SQLException