public class DbUtils extends Object
Modifier and Type | Method and Description |
---|---|
static void |
execute(Connection connection,
String sql)
Utility function for executing the given
sql |
static void |
executeAndClose(PreparedStatement preparedStatement)
Deprecated.
(2.8.0) replaced by
execute(java.sql.Connection, java.lang.String) |
static void |
executeUpdate(Connection connection,
String sql)
Utility function for executing an update
sql statement |
static void |
executeUpdateAndClose(PreparedStatement preparedStatement)
Deprecated.
(2.8.0) replaced by
executeUpdate(java.sql.Connection, java.lang.String) |
static int |
getColumnSize(Connection connection,
String tableName,
String columnName)
Gets the size of the given column
columnName of the table tableName . |
static int |
getColumnType(Connection connection,
String tableName,
String columnName)
Gets the type of the given column
columnName of the table tableName . |
static boolean |
hasColumn(Connection connection,
String tableName,
String columnName)
Tells whether the table
tableName has the column with the given columnName ,
or not. |
static boolean |
hasIndex(Connection connection,
String tableName,
String indexName)
Tells whether the table
tableName has an index with the given indexName , or
not. |
static boolean |
hasTable(Connection connection,
String tableName)
Tells whether the table
tableName exists in the database, or not. |
public static boolean hasTable(Connection connection, String tableName) throws SQLException
tableName
exists in the database, or not.connection
- the connection to the databasetableName
- the name of the table that will be checkedtrue
if the table tableName
exists in the database, false
otherwise.SQLException
- if an error occurred while checking if the table existspublic static boolean hasColumn(Connection connection, String tableName, String columnName) throws SQLException
tableName
has the column with the given columnName
,
or not.connection
- the connection to the databasetableName
- the name of the table that may have the columncolumnName
- the name of the column that will be checkedtrue
if the table tableName
has the column columnName
, false
otherwise.SQLException
- if an error occurred while checking if the table has the columnpublic static boolean hasIndex(Connection connection, String tableName, String indexName) throws SQLException
tableName
has an index with the given indexName
, or
not.connection
- the connection to the databasetableName
- the name of the table that may have the indexindexName
- the name of the index that will be checkedtrue
if the table tableName
has the index indexName
, false
otherwise.SQLException
- if an error occurred while checking if the table has the indexpublic static int getColumnType(Connection connection, String tableName, String columnName) throws SQLException
columnName
of the table tableName
.connection
- the connection to the databasetableName
- the name of the table that has the columncolumnName
- the name of the column that will be used to get the typeSQLException
- if an error occurred while checking the type of the columnpublic static int getColumnSize(Connection connection, String tableName, String columnName) throws SQLException
columnName
of the table tableName
.connection
- the connection to the databasetableName
- the name of the table that has the columncolumnName
- the name of the column that will be used to get the sizeSQLException
- if an error occurred while checking the size of the column@Deprecated public static void executeAndClose(PreparedStatement preparedStatement) throws SQLException
execute(java.sql.Connection, java.lang.String)
preparedStatement
.preparedStatement
- the statement that will be executed and immediately closedSQLException
- if error occurred while executing the given preparedStatement
Statement.close()
,
PreparedStatement.execute()
public static void execute(Connection connection, String sql) throws SQLException
sql
connection
- the database connection to usesql
- the sql statement to runSQLException
- if error occurred while executing the given sql
@Deprecated public static void executeUpdateAndClose(PreparedStatement preparedStatement) throws SQLException
executeUpdate(java.sql.Connection, java.lang.String)
preparedStatement
.preparedStatement
- the statement that will be executed and immediately closedSQLException
- if error occurred while executing the given preparedStatement
Statement.close()
,
PreparedStatement.executeUpdate()
public static void executeUpdate(Connection connection, String sql) throws SQLException
sql
statementconnection
- the database connection to usesql
- the sql statement to runSQLException
- if error occurred while executing the given sql