Package io.jmix.reports.yarg.util.db
Class DbUtils
java.lang.Object
io.jmix.reports.yarg.util.db.DbUtils
A collection of JDBC helper methods. This class is thread safe.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
close
(Connection conn) Close aConnection
, avoid closing if null.static void
Close aResultSet
, avoid closing if null.static void
Close aStatement
, avoid closing if null.static void
closeQuietly
(Connection conn) Close aConnection
, avoid closing if null and hide any SQLExceptions that occur.static void
closeQuietly
(Connection conn, Statement stmt, ResultSet rs) Close aConnection
,Statement
andResultSet
.static void
Close aResultSet
, avoid closing if null and hide any SQLExceptions that occur.static void
closeQuietly
(Statement stmt) Close aStatement
, avoid closing if null and hide any SQLExceptions that occur.static void
commitAndClose
(Connection conn) Commits aConnection
then closes it, avoid closing if null.static void
Commits aConnection
then closes it, avoid closing if null and hide any SQLExceptions that occur.static boolean
loadDriver
(String driverClassName) Loads and registers a database driver class.static void
Print the stack trace for a SQLException to STDERR.static void
Print the stack trace for a SQLException to a specified PrintWriter.static void
printWarnings
(Connection conn) Print warnings on a Connection to STDERR.static void
printWarnings
(Connection conn, PrintWriter pw) Print warnings on a Connection to a specified PrintWriter.static void
rollback
(Connection conn) Rollback any changes made on the given connection.static void
rollbackAndClose
(Connection conn) Performs a rollback on theConnection
then closes it, avoid closing if null.static void
Performs a rollback on theConnection
then closes it, avoid closing if null and hide any SQLExceptions that occur.
-
Method Details
-
close
Close aConnection
, avoid closing if null.- Parameters:
conn
- Connection to close.- Throws:
SQLException
- if a database access error occurs
-
close
Close aResultSet
, avoid closing if null.- Parameters:
rs
- ResultSet to close.- Throws:
SQLException
- if a database access error occurs
-
close
Close aStatement
, avoid closing if null.- Parameters:
stmt
- Statement to close.- Throws:
SQLException
- if a database access error occurs
-
closeQuietly
Close aConnection
, avoid closing if null and hide any SQLExceptions that occur.- Parameters:
conn
- Connection to close.
-
closeQuietly
Close aConnection
,Statement
andResultSet
. Avoid closing if null and hide any SQLExceptions that occur.- Parameters:
conn
- Connection to close.stmt
- Statement to close.rs
- ResultSet to close.
-
closeQuietly
Close aResultSet
, avoid closing if null and hide any SQLExceptions that occur.- Parameters:
rs
- ResultSet to close.
-
closeQuietly
Close aStatement
, avoid closing if null and hide any SQLExceptions that occur.- Parameters:
stmt
- Statement to close.
-
commitAndClose
Commits aConnection
then closes it, avoid closing if null.- Parameters:
conn
- Connection to close.- Throws:
SQLException
- if a database access error occurs
-
commitAndCloseQuietly
Commits aConnection
then closes it, avoid closing if null and hide any SQLExceptions that occur.- Parameters:
conn
- Connection to close.
-
loadDriver
Loads and registers a database driver class. If this succeeds, it returns true, else it returns false.- Parameters:
driverClassName
- of driver to load- Returns:
- boolean
true
if the driver was found, otherwisefalse
-
printStackTrace
Print the stack trace for a SQLException to STDERR.- Parameters:
e
- SQLException to print stack trace of
-
printStackTrace
Print the stack trace for a SQLException to a specified PrintWriter.- Parameters:
e
- SQLException to print stack trace ofpw
- PrintWriter to print to
-
printWarnings
Print warnings on a Connection to STDERR.- Parameters:
conn
- Connection to print warnings from
-
printWarnings
Print warnings on a Connection to a specified PrintWriter.- Parameters:
conn
- Connection to print warnings frompw
- PrintWriter to print to
-
rollback
Rollback any changes made on the given connection.- Parameters:
conn
- Connection to rollback. A null value is legal.- Throws:
SQLException
- if a database access error occurs
-
rollbackAndClose
Performs a rollback on theConnection
then closes it, avoid closing if null.- Parameters:
conn
- Connection to rollback. A null value is legal.- Throws:
SQLException
- if a database access error occurs- Since:
- DbUtils 1.1
-
rollbackAndCloseQuietly
Performs a rollback on theConnection
then closes it, avoid closing if null and hide any SQLExceptions that occur.- Parameters:
conn
- Connection to rollback. A null value is legal.- Since:
- DbUtils 1.1
-