|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jenkov.mrpersister.util.JdbcUtil
public class JdbcUtil
Constructor Summary | |
---|---|
JdbcUtil()
|
Method Summary | |
---|---|
static void |
close(java.sql.Connection connection)
Closes the provided connection, if it is not already closed. |
static void |
close(java.sql.Connection connection,
java.sql.Statement statement,
java.sql.ResultSet result)
Closes the ResultSet , then the Statement or
PreparedStatement , and finally the Connection
in the same sequence as mentioned here. |
static void |
close(IGenericDao dao)
Closes the connection enclosed in the given IGenericDao instance. |
static void |
close(java.sql.ResultSet result)
Closes the provided ResultSet . |
static void |
close(java.sql.Statement statement)
Closes the provided Statement or PreparedStatement . |
static void |
closeIgnore(java.sql.Connection connection)
Closes the provided connection. |
static void |
closeIgnore(java.sql.Connection connection,
java.sql.Statement statement,
java.sql.ResultSet result)
Closes the ResultSet , then the Statement or
PreparedStatement , and finally the Connection
in the same sequence as mentioned here. |
static void |
closeIgnore(IGenericDao dao)
Closes the connection enclosed in the given IGenericDao instance. |
static void |
closeIgnore(java.sql.ResultSet result)
Closes the provided ResultSet . |
static void |
closeIgnore(java.sql.Statement statement)
Closes the provided Statement or PreparedStatement . |
static java.sql.Connection |
getConnection(java.lang.String driverClass,
java.lang.String url,
java.lang.String user,
java.lang.String password)
Opens a connection to the specified database using the JDBC driver class , the url, the user name, and the password provided. |
static void |
insertParameter(java.sql.PreparedStatement statement,
int index,
java.lang.Object parameter)
Inserts a parameter into a PreparedStatement on the given index. |
static void |
insertParameters(java.sql.PreparedStatement statement,
java.util.Collection parameters)
Inserts all parameters in the collection into the PreparedStatement
instance in the sequence their are returned by the collection's iterator. |
static void |
insertParameters(java.sql.PreparedStatement statement,
java.lang.Object[] parameters)
Inserts all parameters in the array into the PreparedStatement
instance in the sequence their are located in the array. |
static int |
parameterCount(java.sql.PreparedStatement statement)
|
static java.sql.PreparedStatement |
prepareStatement(java.sql.Connection connection,
java.lang.String sql)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public JdbcUtil()
Method Detail |
---|
public static void close(IGenericDao dao) throws PersistenceException
IGenericDao
instance.
If the dao parameter is null, or its enclosed connection reference is null,
nothing happens.
dao
- The dao to close the enclosed connection of.
PersistenceException
- If an error occurs when closing the connection.public static void closeIgnore(IGenericDao dao)
IGenericDao
instance.
If the dao parameter is null, or its enclosed connection reference is null,
nothing happens. Any exceptions thrown while closing the connection are ignored.
dao
- The dao to close the enclosed connection of.public static java.sql.Connection getConnection(java.lang.String driverClass, java.lang.String url, java.lang.String user, java.lang.String password) throws java.lang.ClassNotFoundException, java.sql.SQLException, java.lang.IllegalAccessException, java.lang.InstantiationException
driverClass
- The name of the JDBC driver class.url
- The URL to the database server / JDBC connection URL.user
- The user name to be used to connect to the database.password
- The password of the user to be used to connect to the database.
java.lang.ClassNotFoundException
- If the JDBC driver class could not be found (is not on the classpath)
java.sql.SQLException
- If something goes wrong during the connection, for instance if the
database/catalogue name in the URL is not recognized by the database server.
java.lang.IllegalAccessException
- If your application does not have permission to
instantiate the database driver.
java.lang.InstantiationException
- If an instance of the JDBC driver class could not be created.public static void close(java.sql.Connection connection) throws PersistenceException
connection
- The connection to close.
PersistenceException
- If an SQLException is thrown when calling
connection.close()
public static void closeIgnore(java.sql.Connection connection)
connection
- The connection to close.public static void close(java.sql.Statement statement) throws PersistenceException
Statement
or PreparedStatement
.
If you provide a null statement nothing happens.
statement
- The Statement
or PreparedStatement
to close.
PersistenceException
- If an SQLException is thrown when calling
statement.close()
public static void closeIgnore(java.sql.Statement statement)
Statement
or PreparedStatement
.
If you provide a null statement nothing happens.
Any exceptions thrown while closing the Statement
or
PreparedStatement
are ignored.
statement
- The Statement
or PreparedStatement
to close.public static void close(java.sql.ResultSet result) throws PersistenceException
ResultSet
. If you provide a null result set nothing happens.
result
- The ResultSet
to close.
PersistenceException
- If an SQLException is thrown when calling
result.close()
public static void closeIgnore(java.sql.ResultSet result)
ResultSet
. If you provide a null result set nothing happens.
Any exceptions thrown when closing
the ResultSet
are ignored.
result
- The ResultSet
to close.public static void close(java.sql.Connection connection, java.sql.Statement statement, java.sql.ResultSet result) throws PersistenceException
ResultSet
, then the Statement
or
PreparedStatement
, and finally the Connection
in the same sequence as mentioned here. If any of the parameters are null they
will be ignored (not attempted closed).
connection
- The Connection
to close.statement
- The Statement
or PreparedStatement
to close.result
- The ResultSet
to close.
PersistenceException
- If one or more SQLExceptions are thrown when closing
the result set, statement or connection. The error messages from
all thrown exceptions are collected and included in the one
PersistenceException that is thrown.public static void closeIgnore(java.sql.Connection connection, java.sql.Statement statement, java.sql.ResultSet result)
ResultSet
, then the Statement
or
PreparedStatement
, and finally the Connection
in the same sequence as mentioned here. If any of the parameters are null they
will be ignored (not attempted closed). All exceptions thrown are ignored.
connection
- The Connection
to close.statement
- The Statement
or PreparedStatement
to close.result
- The ResultSet
to close.public static void insertParameter(java.sql.PreparedStatement statement, int index, java.lang.Object parameter) throws PersistenceException
PreparedStatement
on the given index. This
method will try to determine what class the parameter is instance of,
and call the coresponding setter method on the PreparedStatement
.
statement
- The PreparedStatement
to insert the parameter into.parameter
- The parameter to be inserted.index
- The index of the parameter in the PreparedStatement
.
PersistenceException
- If anything goes wrong when calling the setter method on
the PreparedStatement
instance.
java.lang.IllegalArgumentException
- If the parameter class is not supported.public static void insertParameters(java.sql.PreparedStatement statement, java.util.Collection parameters) throws PersistenceException
PreparedStatement
instance in the sequence their are returned by the collection's iterator.
statement
- The PreparedStatement
to insert the parameters into.parameters
- The parameters to insert.
PersistenceException
- If anything goes wrong during the insertion of the parameters.public static void insertParameters(java.sql.PreparedStatement statement, java.lang.Object[] parameters) throws PersistenceException
PreparedStatement
instance in the sequence their are located in the array.
statement
- The PreparedStatement
to insert the parameters intoparameters
- The parameters to insert.
PersistenceException
- If anything goes wrong during the insertion of the parameters.public static java.sql.PreparedStatement prepareStatement(java.sql.Connection connection, java.lang.String sql) throws PersistenceException
PersistenceException
public static int parameterCount(java.sql.PreparedStatement statement) throws PersistenceException
PersistenceException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |