com.interface21.jdbc.core
Class JdbcHelper

java.lang.Object
  |
  +--com.interface21.jdbc.core.JdbcHelper

public class JdbcHelper
extends java.lang.Object

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.

Since:
May 30, 2001
Author:
Rod Johnson

Constructor Summary
JdbcHelper(javax.sql.DataSource dataSource)
          Creates a new JDBCHelper
 
Method Summary
 java.lang.Object[] getIDs(java.lang.String sql, java.lang.Class requiredType, java.lang.Object[] params)
           
 int[] getIDs(java.lang.String sql, java.lang.Object[] params)
          Run the given SQL SELECT to return a ResultSet of an array of IDs.
 JdbcTemplate getTemplate()
           
 int runSQLFunction(java.lang.String sql)
           
 java.lang.Object runSQLFunction(java.lang.String sql, java.lang.Class requiredType)
          Run the given SQL function.
 java.lang.Object runSQLFunction(java.lang.String sql, java.lang.Class requiredType, int[] types, java.lang.Object[] args)
           
 int runSQLFunction(java.lang.String sql, int[] types, java.lang.Object[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JdbcHelper

public JdbcHelper(javax.sql.DataSource dataSource)
Creates a new JDBCHelper
Method Detail

runSQLFunction

public int runSQLFunction(java.lang.String sql)

runSQLFunction

public int runSQLFunction(java.lang.String sql,
                          int[] types,
                          java.lang.Object[] args)

runSQLFunction

public java.lang.Object runSQLFunction(java.lang.String sql,
                                       java.lang.Class requiredType,
                                       int[] types,
                                       java.lang.Object[] args)
                                throws javax.ejb.EJBException

runSQLFunction

public java.lang.Object runSQLFunction(java.lang.String sql,
                                       java.lang.Class requiredType)
                                throws javax.ejb.EJBException
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:
javax.ejb.EJBException - if there is a problem executing the function

getIDs

public int[] getIDs(java.lang.String sql,
                    java.lang.Object[] params)
             throws javax.ejb.EJBException
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 function result as.
Throws:
javax.ejb.EJBException - if there is a problem executing the function

getIDs

public java.lang.Object[] getIDs(java.lang.String sql,
                                 java.lang.Class requiredType,
                                 java.lang.Object[] params)
                          throws javax.ejb.EJBException

getTemplate

public JdbcTemplate getTemplate()


Rod Johnson and Spring contributors 2001-2003.