org.springframework.jdbc.core
Class JdbcHelper
- public class JdbcHelper
Utility class to use for JDBC queries from J2EE applications.
This avoids the need for writing raw SQL.
Connections are obtained using JNDI data sources,
so this class will only work within a J2EE application.
It is probably best used from a stateless session bean; however
it could also be used from within a web application.
- Author:
- Rod Johnson
- Version: $Id: JdbcHelper.java,v 1.3 2003/08/26 17:21:52 jhoeller Exp $
- Since: May 30, 2001
| Constructor Summary |
JdbcHelper(DataSource dataSource) Create new JdbcHelper for the given DataSource. |
| Method Summary |
int[] | getIDs(String sql, Object[] params) Run the given SQL SELECT to return a ResultSet of an array of IDs. |
Object[] | getIDs(String sql, Class requiredType, Object[] params) Run the given SQL SELECT to return a ResultSet of an array of IDs. |
JdbcTemplate | getTemplate() |
int | runSQLFunction(String sql) |
Object | runSQLFunction(String sql, Class requiredType) Run the given SQL function. |
int | runSQLFunction(String sql, int[] types, Object[] args) |
Object | runSQLFunction(String sql, Class requiredType, int[] types, Object[] args) |
JdbcHelper
public JdbcHelper(DataSource dataSource)
- Create new JdbcHelper for the given DataSource.
- Parameters:
- dataSource - DataSource to use
getIDs
public int[] getIDs(String sql, Object[] params)
throws org.springframework.dao.DataAccessException
- Run the given SQL SELECT to return a ResultSet of an array of IDs.
- Parameters:
- sql - SQL function, such as SELECT MAX(USER_ID) FROM USERS.
Must return only one row.
- params - prepared statement parameters
- Throws:
- DataAccessException - if there is a problem executing the function
getIDs
public Object[] getIDs(String sql, Class requiredType, Object[] params)
throws org.springframework.dao.DataAccessException
- Run the given SQL SELECT to return a ResultSet of an array of IDs.
- Parameters:
- sql - SQL function, such as SELECT MAX(USER_ID) FROM USERS.
Must return only one row.
- requiredType - the class we need to extract the results as
- params - prepared statement parameters
- Throws:
- DataAccessException - if there is a problem executing the function
getTemplate
public JdbcTemplate getTemplate()
runSQLFunction
public int runSQLFunction(String sql)
runSQLFunction
public Object runSQLFunction(String sql, Class requiredType)
throws org.springframework.dao.DataAccessException
- Run the given SQL function.
- Parameters:
- sql - SQL function, such as SELECT MAX(USER_ID) FROM USERS.
Must return only one row.
- requiredType - the class we need to extract the function result as.
- Throws:
- DataAccessException - if there is a problem executing the function
runSQLFunction
public int runSQLFunction(String sql, int[] types, Object[] args)
runSQLFunction
public Object runSQLFunction(String sql, Class requiredType, int[] types, Object[] args)
throws org.springframework.dao.DataAccessException
to Class org.springframework.jdbc.core.ColumnExtractor- Column extractor to use
to Class org.springframework.jdbc.core.JdbcTemplate