Class SQLUtils
java.lang.Object
ru.bgcrm.util.sql.SQLUtils
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final voidSafe closing of DB connection if it isn'tnulland not closed already.static final voidcloseConnection(Connection... con) Safe closing of DB connections if each of them isn'tnulland not closed alreadystatic booleancolumnExist(Connection con, String table, String column) static final voidCommits a single DB connectionstatic intgetConnectionId(Connection connection) getTableColumns(Connection con, String tableName) static final StringjavaDateFormatToSql(String format) Converts aSimpleDateFormat-style date format to the format for the MySQL DATE_FORMAT functionstatic intstatic final voidsetAutoCommit(Connection connection) Sets automatic commit (autocommit) for the given connectionstatic booleantableExists(Connection con, String tableName) Checks whether a table exists in the DB
-
Field Details
-
tables
-
-
Constructor Details
-
SQLUtils
public SQLUtils()
-
-
Method Details
-
closeConnection
Safe closing of DB connection if it isn'tnulland not closed already. Faster comparing tocloseConnection(Connection...), doesn't create arrays on every call.- Parameters:
con- connection,nullsafe
-
closeConnection
Safe closing of DB connections if each of them isn'tnulland not closed already- Parameters:
con- connections
-
getConnectionId
- Throws:
SQLException
-
lastInsertId
- Throws:
SQLException
-
tableExists
Checks whether a table exists in the DB- Parameters:
con- the DB connectiontableName- the checked table name- Returns:
trueif the table exists,falseif it doesn't exist or the DB is not accessible
-
columnExist
-
commitConnection
Commits a single DB connection- Parameters:
con- the connection
-
setAutoCommit
Sets automatic commit (autocommit) for the given connection- Parameters:
connection- the connection
-
javaDateFormatToSql
Converts aSimpleDateFormat-style date format to the format for the MySQL DATE_FORMAT function- Parameters:
format- the input format- Returns:
- the converted format
-
getTableColumns
- Throws:
SQLException
-