public class JdbcUtil extends Object
Modifier and Type | Class and Description |
---|---|
static class |
JdbcUtil.DummyResultSetHandler
Dummy resultset handler callback; literally does nothing
|
static interface |
JdbcUtil.ResultSetHandler
Result set handler callback interface for
executeQuery(Connection, String, ResultSetHandler, int) |
static interface |
JdbcUtil.StatementHandler
Statement handler callback interface for
executeUpdate(Connection, String, StatementHandler) |
Constructor and Description |
---|
JdbcUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
executeQuery(Connection c,
String sql,
JdbcUtil.ResultSetHandler handler,
int fetchSize)
Execute query an passes the ResultSet to the given handler on each record
|
static void |
executeQuery(Connection c,
String sql,
JdbcUtil.ResultSetHandler handler,
int limit,
int fetchSize)
Execute query an passes the ResultSet to the given handler on each record
|
static int |
executeUpdate(Connection con,
String sql)
Execute update
|
static int |
executeUpdate(Connection con,
String sql,
JdbcUtil.StatementHandler sh)
Executes an update using a prepared statement.
|
public static int executeUpdate(Connection con, String sql) throws SQLException
con
- connectionsql
- sql statementSQLException
- in case of a db issuepublic static int executeUpdate(Connection con, String sql, JdbcUtil.StatementHandler sh) throws SQLException
final int myid = 42; JdbcUtil.executeUpdate(con, "select * from table where id = ?", new StatementHandler() { public void prepare(PreparedStatement stmt) throws SQLException { stmt.setInt(1, myid); } });
con
- connectionsql
- sql prepared statement (i.e. may contain the "?" placeholders to be populated by the sh handlersh
- JdbcUtil.StatementHandler
instance to setup the prepared statementSQLException
- in case of a db issuepublic static void executeQuery(Connection c, String sql, JdbcUtil.ResultSetHandler handler, int limit, int fetchSize) throws SQLException, IOException
c
- JDBC connectionsql
- sql statementhandler
- Jdbc ResultSet handlerlimit
- maximum number of rows to processfetchSize
- max fetch sizeSQLException
- in case of a db issueIOException
public static void executeQuery(Connection c, String sql, JdbcUtil.ResultSetHandler handler, int fetchSize) throws SQLException, IOException
c
- JDBC connectionsql
- sql statementhandler
- Jdbc ResultSet handlerfetchSize
- max fetch sizeSQLException
- in case of a db issueIOException
Copyright © 2014. All rights reserved.