The DBUtil library from Apache provides a set of class for doing a variety of standard database tasks.
eg. To make a query becomes as simple as the following, providing the result set as a List of arrays where each list elements contains a row.
QueryRunner runner = new QueryRunner();
ArrayListHandler handler = new ArrayListHandler();
List<Object[]> result = runner.query(connection,
"SELECT * FROM MyTable WHERE name=?", handler, "Joe Smith");
DbUtils.close(conn);
written by objects
\\ tags: apache, jdbc DBUtil, list, query, ResultSet
The Connection class has a setReadOnly() that hints to the database that the connection is read only. This will enable any possible database optimisation.
Connection connection = DriverManager.getConnection(
connectionString, properties);
connection.setReadOnly(true);
written by objects
\\ tags: connection, database
If you are pulling a value from a database ResultSet it is somethimes not possible to check the value returned to determine if the value in the database was null. In these cases you can use the wasNull() method to check.
The wasNull() method will return true if the value in the database was NULL for the last value retrieved from ResultSet.
Here is an example of its usage.
ResultSet rs = statement.executeQuery();
int value = rs.getInt(1);
if (rs.wasNull(1))
{
// Database contains NULL
}
written by objects
\\ tags: database, null, ResultSet
Recent Comments