org.springframework.jdbc.core

Class JdbcTemplate

Implemented Interfaces:
InitializingBean, JdbcOperations

public class JdbcTemplate
extends JdbcAccessor
implements JdbcOperations

This is the central class in the JDBC core package. It simplifies the use of JDBC and helps to avoid common errors. It executes core JDBC workflow, leaving application code to provide SQL and extract results. This class executes SQL queries or updates, initiating iteration over ResultSets and catching JDBC exceptions and translating them to the generic, more informative exception hierarchy defined in the org.springframework.dao package.

Code using this class need only implement callback interfaces, giving them a clearly defined contract. The PreparedStatementCreator callback interface creates a prepared statement given a Connection provided by this class, providing SQL and any necessary parameters. The RowCallbackHandler interface extracts values from each row of a ResultSet.

Can be used within a service implementation via direct instantiation with a DataSource reference, or get prepared in an application context and given to services as bean reference. Note: The DataSource should always be configured as a bean in the application context, in the first case given to the service directly, in the second case to the prepared template.

The motivation and design of this class is discussed in detail in Expert One-On-One J2EE Design and Development by Rod Johnson (Wrox, 2002).

Because this class is parameterizable by the callback interfaces and the SQLExceptionTranslator interface, it isn't necessary to subclass it. All operations performed by this class are logged at debug level.

Since:
May 3, 2001
See Also:
ResultSetExtractor, RowCallbackHandler, RowMapper, org.springframework.dao, org.springframework.jdbc.datasource, org.springframework.jdbc.object

Field Summary

Fields inherited from class org.springframework.jdbc.support.JdbcAccessor

logger

Constructor Summary

JdbcTemplate()
Construct a new JdbcTemplate for bean usage.
JdbcTemplate(DataSource dataSource)
Construct a new JdbcTemplate, given a DataSource to obtain connections from.
JdbcTemplate(DataSource dataSource, boolean lazyInit)
Construct a new JdbcTemplate, given a DataSource to obtain connections from.

Method Summary

protected void
applyStatementSettings(Statement stmt)
Prepare the given JDBC Statement (or PreparedStatement or CallableStatement), applying statement settings such as fetch size, max rows, and query timeout.
int[]
batchUpdate(String sql, BatchPreparedStatementSetter pss)
int[]
batchUpdate(String[] sql)
Map<K,V>
call(CallableStatementCreator csc, List<E> declaredParameters)
protected Connection
createConnectionProxy(Connection con)
Create a close-suppressing proxy for the given JDBC Connection.
void
execute(String sql)
Object
execute(String callString, CallableStatementCallback action)
Object
execute(String sql, PreparedStatementCallback action)
Object
execute(CallableStatementCreator csc, CallableStatementCallback action)
Object
execute(ConnectionCallback action)
Object
execute(PreparedStatementCreator psc, PreparedStatementCallback action)
Object
execute(StatementCallback action)
protected Map<K,V>
extractOutputParameters(CallableStatement cs, List<E> parameters)
Extract output parameters from the completed stored procedure.
protected Map<K,V>
extractReturnedResultSets(CallableStatement cs, List<E> parameters, int updateCount)
Extract returned ResultSets from the completed stored procedure.
protected RowMapper
getColumnMapRowMapper()
Create a new RowMapper for reading columns as key-value pairs.
int
getFetchSize()
Return the fetch size specified for this JdbcTemplate.
int
getMaxRows()
Return the maximum number of rows specified for this JdbcTemplate.
NativeJdbcExtractor
getNativeJdbcExtractor()
Return the current NativeJdbcExtractor implementation.
protected RowMapper
getSingleColumnRowMapper(Class<T> requiredType)
Create a new RowMapper for reading result objects from a single column.
boolean
isIgnoreWarnings()
Return whether or not we ignore SQLWarnings.
protected Map<K,V>
processResultSet(ResultSet rs, ResultSetSupportingSqlParameter param)
Process the given ResultSet from a stored procedure.
Object
query(String sql, Object[] args, int[] argTypes, ResultSetExtractor rse)
void
query(String sql, Object[] args, int[] argTypes, RowCallbackHandler rch)
List<E>
query(String sql, Object[] args, int[] argTypes, RowMapper rowMapper)
Object
query(String sql, Object[] args, ResultSetExtractor rse)
void
query(String sql, Object[] args, RowCallbackHandler rch)
List<E>
query(String sql, Object[] args, RowMapper rowMapper)
Object
query(String sql, PreparedStatementSetter pss, ResultSetExtractor rse)
void
query(String sql, PreparedStatementSetter pss, RowCallbackHandler rch)
List<E>
query(String sql, PreparedStatementSetter pss, RowMapper rowMapper)
Object
query(String sql, ResultSetExtractor rse)
void
query(String sql, RowCallbackHandler rch)
List<E>
query(String sql, RowMapper rowMapper)
protected Object
query(PreparedStatementCreator psc, PreparedStatementSetter pss, ResultSetExtractor rse)
Query using a prepared statement, allowing for a PreparedStatementCreator and a PreparedStatementSetter.
Object
query(PreparedStatementCreator psc, ResultSetExtractor rse)
void
query(PreparedStatementCreator psc, RowCallbackHandler rch)
List<E>
query(PreparedStatementCreator psc, RowMapper rowMapper)
int
queryForInt(String sql)
int
queryForInt(String sql, Object[] args)
int
queryForInt(String sql, Object[] args, int[] argTypes)
List<E>
queryForList(String sql)
List<E>
queryForList(String sql, Class<T> elementType)
List<E>
queryForList(String sql, Object[] args)
List<E>
queryForList(String sql, Object[] args, int[] argTypes)
List<E>
queryForList(String sql, Object[] args, int[] argTypes, Class<T> elementType)
List<E>
queryForList(String sql, Object[] args, Class<T> elementType)
long
queryForLong(String sql)
long
queryForLong(String sql, Object[] args)
long
queryForLong(String sql, Object[] args, int[] argTypes)
Map<K,V>
queryForMap(String sql)
Map<K,V>
queryForMap(String sql, Object[] args)
Map<K,V>
queryForMap(String sql, Object[] args, int[] argTypes)
Object
queryForObject(String sql, Class<T> requiredType)
Object
queryForObject(String sql, Object[] args, int[] argTypes, Class<T> requiredType)
Object
queryForObject(String sql, Object[] args, int[] argTypes, RowMapper rowMapper)
Object
queryForObject(String sql, Object[] args, Class<T> requiredType)
Object
queryForObject(String sql, Object[] args, RowMapper rowMapper)
Object
queryForObject(String sql, RowMapper rowMapper)
SqlRowSet
queryForRowSet(String sql)
SqlRowSet
queryForRowSet(String sql, Object[] args)
SqlRowSet
queryForRowSet(String sql, Object[] args, int[] argTypes)
void
setFetchSize(int fetchSize)
Set the fetch size for this JdbcTemplate.
void
setIgnoreWarnings(boolean ignoreWarnings)
Set whether or not we want to ignore SQLWarnings.
void
setMaxRows(int maxRows)
Set the maximum number of rows for this JdbcTemplate.
void
setNativeJdbcExtractor(NativeJdbcExtractor extractor)
Set a NativeJdbcExtractor to extract native JDBC objects from wrapped handles.
int
update(String sql)
int
update(String sql, Object[] args)
int
update(String sql, Object[] args, int[] argTypes)
int
update(String sql, PreparedStatementSetter pss)
int
update(PreparedStatementCreator psc)
protected int
update(PreparedStatementCreator psc, PreparedStatementSetter pss)
int
update(PreparedStatementCreator psc, KeyHolder generatedKeyHolder)

Methods inherited from class org.springframework.jdbc.support.JdbcAccessor

afterPropertiesSet, getDataSource, getExceptionTranslator, isLazyInit, setDataSource, setDatabaseProductName, setExceptionTranslator, setLazyInit

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

JdbcTemplate

public JdbcTemplate()
Construct a new JdbcTemplate for bean usage. Note: The DataSource has to be set before using the instance. This constructor can be used to prepare a JdbcTemplate via a BeanFactory, typically setting the DataSource via setDataSource.
See Also:
JdbcTemplate
Usages and Demos :

View More Examples of JdbcTemplate()
   1:     public void testJdbcDaoSupportWithJdbcTemplate() throws Exception {
   2:         JdbcTemplate template = new JdbcTemplate();
   3:         final List test = new ArrayList();
   4:         JdbcDaoSupport dao = new JdbcDaoSupport() {
   5:             protected void initDao() {

View Full Code Here
   1:        final ArrayList results = new ArrayList();
   2:        JdbcTemplate template = new JdbcTemplate();
   3:        template.setDataSource(this.getDataSource());
   4:         ...
   5:        final Bike bike = new Bike();
   6:        JdbcTemplate template = new JdbcTemplate();
   7:        template.setDataSource(this.getDataSource());
   8:         ...
   9:           final Bike bike = new Bike();
  10:           JdbcTemplate template = new JdbcTemplate();
  11:           template.setDataSource(this.getDataSource());

View Full Code Here
   1:     public void initBase() {
   2:         JdbcTemplate tpl = new JdbcTemplate();
   3:         tpl.setDataSource(this.getDataSource());
   4:         ...
   5:         try {
   6:             JdbcTemplate tpl = new JdbcTemplate();
   7:             tpl.setDataSource(this.getDataSource());
   8:             tpl.batchUpdate(INSERT_SQL,    new BatchSetter(countries, locale));
   9:         } catch (DataAccessException e) {

View Full Code Here
   1:         replay();    
   2:         JdbcTemplate t = new JdbcTemplate();
   3:         t.setDataSource(mockDataSource);
   4:         StoredProcedureConfiguredViaJdbcTemplate sp = new StoredProcedureConfiguredViaJdbcTemplate(t);
   5:     

View Full Code Here

JdbcTemplate

public JdbcTemplate(DataSource dataSource)
Construct a new JdbcTemplate, given a DataSource to obtain connections from. Note: This will not trigger initialization of the exception translator.
Parameters:
dataSource - JDBC DataSource to obtain connections from
Usages and Demos :

View More Examples of JdbcTemplate(DataSource dataSource)
   1: 
   2:     JdbcTemplate jt = new JdbcTemplate(dataSource);
   3:     jt.execute("delete from mytable");
   4:     jt.execute("insert into mytable (id, name) values(1, 'John')");
   5:     jt.execute("insert into mytable (id, name) values(2, 'Jane')");

View Full Code Here
   1:             context.getBean("dataSource");
   2:         JdbcTemplate jdbcTemplate = new JdbcTemplate(datsSource);
   3:         
   4:                 
   5:         jdbcTemplate.execute("select * from pixuser");

View Full Code Here
   1:     protected JdbcTemplate createJdbcTemplate(DataSource dataSource) {
   2:         JdbcTemplate jt = new JdbcTemplate(dataSource);
   3:         this.simpleJdbcTemplate = new SimpleJdbcTemplate(jt);
   4:         return jt;
   5:     }

View Full Code Here
   1:     public final void setDataSource(final DataSource dataSource) {
   2:         this.jdbcTemplate = new JdbcTemplate(dataSource);
   3:     }
   4: 
   5:     protected final JdbcTemplate getJdbcTemplate() {

View Full Code Here
   1:     public void testCallReserveSeat() {
   2:         JdbcTemplate jt = new JdbcTemplate(ds);
   3:         jt.execute("delete from seat_status");
   4:         ...
   5:     public void testCallReserveSeats() {
   6:         JdbcTemplate jt = new JdbcTemplate(ds);
   7:         jt.execute("delete from seat_status");
   8:         Integer[] numarr = {new Integer(2), new Integer(3)};
   9:         CallReserveSeats proc = new CallReserveSeats(ds);

View Full Code Here

JdbcTemplate

public JdbcTemplate(DataSource dataSource,
                    boolean lazyInit)
Construct a new JdbcTemplate, given a DataSource to obtain connections from. Note: Depending on the "lazyInit" flag, initialization of the exception translator will be triggered.
Parameters:
dataSource - JDBC DataSource to obtain connections from
lazyInit - whether to lazily initialize the SQLExceptionTranslator

Method Details

applyStatementSettings

protected void applyStatementSettings(Statement stmt)
            throws SQLException
Prepare the given JDBC Statement (or PreparedStatement or CallableStatement), applying statement settings such as fetch size, max rows, and query timeout.
Parameters:
stmt - the JDBC Statement to prepare

batchUpdate

public int[] batchUpdate(String sql,
                         BatchPreparedStatementSetter pss)
            throws DataAccessException
Specified by:
batchUpdate in interface JdbcOperations

batchUpdate

public int[] batchUpdate(String[] sql)
            throws DataAccessException
Specified by:
batchUpdate in interface JdbcOperations

call

public Map<K,V> call(CallableStatementCreator csc,
                List<E> declaredParameters)
            throws DataAccessException
Specified by:
call in interface JdbcOperations

createConnectionProxy

protected Connection createConnectionProxy(Connection con)
Create a close-suppressing proxy for the given JDBC Connection. Called by the execute method.

The proxy also prepares returned JDBC Statements, applying statement settings such as fetch size, max rows, and query timeout.

Parameters:
con - the JDBC Connection to create a proxy for
Returns:
the Connection proxy

execute

public void execute(String sql)
            throws DataAccessException
Specified by:
execute in interface JdbcOperations

execute

public Object execute(String callString,
                      CallableStatementCallback action)
            throws DataAccessException
Specified by:
execute in interface JdbcOperations

execute

public Object execute(String sql,
                      PreparedStatementCallback action)
            throws DataAccessException
Specified by:
execute in interface JdbcOperations

execute

public Object execute(CallableStatementCreator csc,
                      CallableStatementCallback action)
            throws DataAccessException
Specified by:
execute in interface JdbcOperations

execute

public Object execute(ConnectionCallback action)
            throws DataAccessException
Specified by:
execute in interface JdbcOperations

execute

public Object execute(PreparedStatementCreator psc,
                      PreparedStatementCallback action)
            throws DataAccessException
Specified by:
execute in interface JdbcOperations

execute

public Object execute(StatementCallback action)
            throws DataAccessException
Specified by:
execute in interface JdbcOperations

extractOutputParameters

protected Map<K,V> extractOutputParameters(CallableStatement cs,
                                      List<E> parameters)
            throws SQLException
Extract output parameters from the completed stored procedure.
Parameters:
cs - JDBC wrapper for the stored procedure
parameters - parameter list for the stored procedure
Returns:
parameters to the stored procedure

extractReturnedResultSets

protected Map<K,V> extractReturnedResultSets(CallableStatement cs,
                                        List<E> parameters,
                                        int updateCount)
            throws SQLException
Extract returned ResultSets from the completed stored procedure.
Parameters:
cs - JDBC wrapper for the stored procedure
parameters - Parameter list for the stored procedure
Returns:
Map that contains returned results

getColumnMapRowMapper

protected RowMapper getColumnMapRowMapper()
Create a new RowMapper for reading columns as key-value pairs.
Returns:
the RowMapper to use

getFetchSize

public int getFetchSize()
Return the fetch size specified for this JdbcTemplate.

getMaxRows

public int getMaxRows()
Return the maximum number of rows specified for this JdbcTemplate.

getNativeJdbcExtractor

public NativeJdbcExtractor getNativeJdbcExtractor()
Return the current NativeJdbcExtractor implementation.

getSingleColumnRowMapper

protected RowMapper getSingleColumnRowMapper(Class<T> requiredType)
Create a new RowMapper for reading result objects from a single column.
Parameters:
requiredType - the type that each result object is expected to match
Returns:
the RowMapper to use

isIgnoreWarnings

public boolean isIgnoreWarnings()
Return whether or not we ignore SQLWarnings. Default is "true".

processResultSet

protected Map<K,V> processResultSet(ResultSet rs,
                               ResultSetSupportingSqlParameter param)
            throws SQLException
Process the given ResultSet from a stored procedure.
Parameters:
rs - the ResultSet to process
param - the corresponding stored procedure parameter
Returns:
Map that contains returned results

query

public Object query(String sql,
                    Object[] args,
                    int[] argTypes,
                    ResultSetExtractor rse)
            throws DataAccessException
Specified by:
query in interface JdbcOperations

query

public void query(String sql,
                  Object[] args,
                  int[] argTypes,
                  RowCallbackHandler rch)
            throws DataAccessException
Specified by:
query in interface JdbcOperations

query

public List<E> query(String sql,
                  Object[] args,
                  int[] argTypes,
                  RowMapper rowMapper)
            throws DataAccessException
Specified by:
query in interface JdbcOperations

query

public Object query(String sql,
                    Object[] args,
                    ResultSetExtractor rse)
            throws DataAccessException
Specified by:
query in interface JdbcOperations

query

public void query(String sql,
                  Object[] args,
                  RowCallbackHandler rch)
            throws DataAccessException
Specified by:
query in interface JdbcOperations

query

public List<E> query(String sql,
                  Object[] args,
                  RowMapper rowMapper)
            throws DataAccessException
Specified by:
query in interface JdbcOperations

query

public Object query(String sql,
                    PreparedStatementSetter pss,
                    ResultSetExtractor rse)
            throws DataAccessException
Specified by:
query in interface JdbcOperations

query

public void query(String sql,
                  PreparedStatementSetter pss,
                  RowCallbackHandler rch)
            throws DataAccessException
Specified by:
query in interface JdbcOperations

query

public List<E> query(String sql,
                  PreparedStatementSetter pss,
                  RowMapper rowMapper)
            throws DataAccessException
Specified by:
query in interface JdbcOperations

query

public Object query(String sql,
                    ResultSetExtractor rse)
            throws DataAccessException
Specified by:
query in interface JdbcOperations

query

public void query(String sql,
                  RowCallbackHandler rch)
            throws DataAccessException
Specified by:
query in interface JdbcOperations

query

public List<E> query(String sql,
                  RowMapper rowMapper)
            throws DataAccessException
Specified by:
query in interface JdbcOperations

query

protected Object query(PreparedStatementCreator psc,
                       PreparedStatementSetter pss,
                       ResultSetExtractor rse)
            throws DataAccessException
Query using a prepared statement, allowing for a PreparedStatementCreator and a PreparedStatementSetter. Most other query methods use this method, but application code will always work with either a creator or a setter.
Parameters:
psc - Callback handler that can create a PreparedStatement given a Connection
pss - object that knows how to set values on the prepared statement. If this is null, the SQL will be assumed to contain no bind parameters.
rse - object that will extract results.
Returns:
an arbitrary result object, as returned by the ResultSetExtractor
Throws:
DataAccessException - if there is any problem

query

public Object query(PreparedStatementCreator psc,
                    ResultSetExtractor rse)
            throws DataAccessException
Specified by:
query in interface JdbcOperations

query

public void query(PreparedStatementCreator psc,
                  RowCallbackHandler rch)
            throws DataAccessException
Specified by:
query in interface JdbcOperations

query

public List<E> query(PreparedStatementCreator psc,
                  RowMapper rowMapper)
            throws DataAccessException
Specified by:
query in interface JdbcOperations

queryForInt

public int queryForInt(String sql)
            throws DataAccessException
Specified by:
queryForInt in interface JdbcOperations

queryForInt

public int queryForInt(String sql,
                       Object[] args)
            throws DataAccessException
Specified by:
queryForInt in interface JdbcOperations
Usages and Demos :

View More Examples of queryForInt(String sql,Object[] args)
   1: 
   2:     private JdbcTemplate jdbcTemplate;
   3: 
   4:         ...
   5:     public BoxOfficeDBHelper(JdbcTemplate jdbcTemplate) {
   6:         this.jdbcTemplate = jdbcTemplate;
   7:         ...
   8:         Object[] args = new Object[] { new Long(seatId), new Long(bookingId) };
   9:         return jdbcTemplate.queryForInt(sql, args) > 0;
  10:     }
  11:         ...
  12:         Object[] args = new Object[] { new Long(bookingId) };
  13:         int count = jdbcTemplate.queryForInt(sql, args);

View Full Code Here

queryForInt

public int queryForInt(String sql,
                       Object[] args,
                       int[] argTypes)
            throws DataAccessException
Specified by:
queryForInt in interface JdbcOperations

queryForList

public List<E> queryForList(String sql)
            throws DataAccessException
Specified by:
queryForList in interface JdbcOperations

queryForList

public List<E> queryForList(String sql,
                         Class<T> elementType)
            throws DataAccessException
Specified by:
queryForList in interface JdbcOperations

queryForList

public List<E> queryForList(String sql,
                         Object[] args)
            throws DataAccessException
Specified by:
queryForList in interface JdbcOperations

queryForList

public List<E> queryForList(String sql,
                         Object[] args,
                         int[] argTypes)
            throws DataAccessException
Specified by:
queryForList in interface JdbcOperations

queryForList

public List<E> queryForList(String sql,
                         Object[] args,
                         int[] argTypes,
                         Class<T> elementType)
            throws DataAccessException
Specified by:
queryForList in interface JdbcOperations

queryForList

public List<E> queryForList(String sql,
                         Object[] args,
                         Class<T> elementType)
            throws DataAccessException
Specified by:
queryForList in interface JdbcOperations

queryForLong

public long queryForLong(String sql)
            throws DataAccessException
Specified by:
queryForLong in interface JdbcOperations

queryForLong

public long queryForLong(String sql,
                         Object[] args)
            throws DataAccessException
Specified by:
queryForLong in interface JdbcOperations
Usages and Demos :

View More Examples of queryForLong(String sql,Object[] args)
   1: 
   2:     private JdbcTemplate jdbcTemplate;
   3: 
   4:         ...
   5:     public BoxOfficeDBHelper(JdbcTemplate jdbcTemplate) {
   6:         this.jdbcTemplate = jdbcTemplate;
   7:         ...
   8:         };
   9:         return jdbcTemplate.queryForLong(sql, args);
  10:     }
  11:         ...
  12: 
  13:         return jdbcTemplate.queryForLong(sql, args);

View Full Code Here

queryForLong

public long queryForLong(String sql,
                         Object[] args,
                         int[] argTypes)
            throws DataAccessException
Specified by:
queryForLong in interface JdbcOperations

queryForMap

public Map<K,V> queryForMap(String sql)
            throws DataAccessException
Specified by:
queryForMap in interface JdbcOperations

queryForMap

public Map<K,V> queryForMap(String sql,
                       Object[] args)
            throws DataAccessException
Specified by:
queryForMap in interface JdbcOperations

queryForMap

public Map<K,V> queryForMap(String sql,
                       Object[] args,
                       int[] argTypes)
            throws DataAccessException
Specified by:
queryForMap in interface JdbcOperations

queryForObject

public Object queryForObject(String sql,
                             Class<T> requiredType)
            throws DataAccessException
Specified by:
queryForObject in interface JdbcOperations

queryForObject

public Object queryForObject(String sql,
                             Object[] args,
                             int[] argTypes,
                             Class<T> requiredType)
            throws DataAccessException
Specified by:
queryForObject in interface JdbcOperations

queryForObject

public Object queryForObject(String sql,
                             Object[] args,
                             int[] argTypes,
                             RowMapper rowMapper)
            throws DataAccessException
Specified by:
queryForObject in interface JdbcOperations

queryForObject

public Object queryForObject(String sql,
                             Object[] args,
                             Class<T> requiredType)
            throws DataAccessException
Specified by:
queryForObject in interface JdbcOperations

queryForObject

public Object queryForObject(String sql,
                             Object[] args,
                             RowMapper rowMapper)
            throws DataAccessException
Specified by:
queryForObject in interface JdbcOperations

queryForObject

public Object queryForObject(String sql,
                             RowMapper rowMapper)
            throws DataAccessException
Specified by:
queryForObject in interface JdbcOperations

queryForRowSet

public SqlRowSet queryForRowSet(String sql)
            throws DataAccessException
Specified by:
queryForRowSet in interface JdbcOperations
Usages and Demos :

View More Examples of queryForRowSet(String sql)
   1: import org.apache.commons.logging.LogFactory;
   2: import org.springframework.jdbc.core.JdbcTemplate;
   3: import org.springframework.jdbc.support.rowset.SqlRowSet;
   4:         ...
   5:     List runSql(String sql){
   6:         JdbcTemplate jt = new JdbcTemplate(ds);
   7:         ...
   8:         SqlRowSet rows = jt.queryForRowSet(sql);
   9:         List result = new ArrayList();

View Full Code Here

queryForRowSet

public SqlRowSet queryForRowSet(String sql,
                                Object[] args)
            throws DataAccessException
Specified by:
queryForRowSet in interface JdbcOperations

queryForRowSet

public SqlRowSet queryForRowSet(String sql,
                                Object[] args,
                                int[] argTypes)
            throws DataAccessException
Specified by:
queryForRowSet in interface JdbcOperations

setFetchSize

public void setFetchSize(int fetchSize)
Set the fetch size for this JdbcTemplate. This is important for processing large result sets: Setting this higher than the default value will increase processing speed at the cost of memory consumption; setting this lower can avoid transferring row data that will never be read by the application.

Default is 0, indicating to use the JDBC driver's default.


setIgnoreWarnings

public void setIgnoreWarnings(boolean ignoreWarnings)
Set whether or not we want to ignore SQLWarnings. Default is "true".

setMaxRows

public void setMaxRows(int maxRows)
Set the maximum number of rows for this JdbcTemplate. This is important for processing subsets of large result sets, avoiding to read and hold the entire result set in the database or in the JDBC driver if we're never interested in the entire result in the first place (for example, when performing searches that might return a large number of matches).

Default is 0, indicating to use the JDBC driver's default.


setNativeJdbcExtractor

public void setNativeJdbcExtractor(NativeJdbcExtractor extractor)
Set a NativeJdbcExtractor to extract native JDBC objects from wrapped handles. Useful if native Statement and/or ResultSet handles are expected for casting to database-specific implementation classes, but a connection pool that wraps JDBC objects is used (note: any pool will return wrapped Connections).

update

public int update(String sql)
            throws DataAccessException
Specified by:
update in interface JdbcOperations
Usages and Demos :

View More Examples of update(String sql)
   1: import org.springframework.jdbc.core.BatchPreparedStatementSetter;
   2: import org.springframework.jdbc.core.JdbcTemplate;
   3: import org.springframework.jdbc.core.SqlParameter;
   4:         ...
   5:     public void initBase() {
   6:         JdbcTemplate tpl = new JdbcTemplate();
   7:         tpl.setDataSource(this.getDataSource());
   8:         ...
   9:         try {
  10:             tpl.update(dropSql);
  11:             logger.info("'countries' table deleted");
  12:         ...
  13: 
  14:         tpl.update(createSql);

View Full Code Here

update

public int update(String sql,
                  Object[] args)
            throws DataAccessException
Specified by:
update in interface JdbcOperations
Usages and Demos :

View More Examples of update(String sql,Object[] args)
   1: 
   2: import org.springframework.jdbc.core.JdbcTemplate;
   3: import org.springframework.jdbc.core.RowMapper;
   4:         ...
   5: 
   6:         JdbcTemplate jt = getJdbcTemplate();
   7: 
   8:         ...
   9: 
  10:         jt.update(INSERT_PIXUSER_SQL, userParameters);
  11: 
  12:         ...
  13:         };
  14:         jt.update(INSERT_ALBUM_SQL, movieParameters);

View Full Code Here
   1: 
   2:     private JdbcTemplate jdbcTemplate;
   3: 
   4:         ...
   5:     public BoxOfficeDBHelper(JdbcTemplate jdbcTemplate) {
   6:         this.jdbcTemplate = jdbcTemplate;
   7:         ...
   8:         Object[] args = new Object[] { new Long(id), name };
   9:         jdbcTemplate.update(sql, args);
  10:     }
  11:         ...
  12:         };
  13:         jdbcTemplate.update(sql, args);

View Full Code Here

update

public int update(String sql,
                  Object[] args,
                  int[] argTypes)
            throws DataAccessException
Specified by:
update in interface JdbcOperations

update

public int update(String sql,
                  PreparedStatementSetter pss)
            throws DataAccessException
Specified by:
update in interface JdbcOperations
Usages and Demos :

View More Examples of update(String sql,PreparedStatementSetter pss)
   1: 
   2: import org.springframework.jdbc.core.JdbcTemplate;
   3: import org.springframework.jdbc.core.RowMapper;
   4:         ...
   5: 
   6:         JdbcTemplate jt = getJdbcTemplate();
   7: 
   8:         ...
   9: 
  10:         jt.update(INSERT_PIXUSER_SQL, userParameters);
  11: 
  12:         ...
  13:         };
  14:         jt.update(INSERT_ALBUM_SQL, movieParameters);

View Full Code Here
   1: 
   2:     private JdbcTemplate jdbcTemplate;
   3: 
   4:         ...
   5:     public BoxOfficeDBHelper(JdbcTemplate jdbcTemplate) {
   6:         this.jdbcTemplate = jdbcTemplate;
   7:         ...
   8:         Object[] args = new Object[] { new Long(id), name };
   9:         jdbcTemplate.update(sql, args);
  10:     }
  11:         ...
  12:         };
  13:         jdbcTemplate.update(sql, args);

View Full Code Here

update

public int update(PreparedStatementCreator psc)
            throws DataAccessException
Specified by:
update in interface JdbcOperations
Usages and Demos :

View More Examples of update(PreparedStatementCreator psc)
   1: import org.springframework.jdbc.core.BatchPreparedStatementSetter;
   2: import org.springframework.jdbc.core.JdbcTemplate;
   3: import org.springframework.jdbc.core.SqlParameter;
   4:         ...
   5:     public void initBase() {
   6:         JdbcTemplate tpl = new JdbcTemplate();
   7:         tpl.setDataSource(this.getDataSource());
   8:         ...
   9:         try {
  10:             tpl.update(dropSql);
  11:             logger.info("'countries' table deleted");
  12:         ...
  13: 
  14:         tpl.update(createSql);

View Full Code Here

update

protected int update(PreparedStatementCreator psc,
                     PreparedStatementSetter pss)
            throws DataAccessException

update

public int update(PreparedStatementCreator psc,
                  KeyHolder generatedKeyHolder)
            throws DataAccessException
Specified by:
update in interface JdbcOperations
Usages and Demos :

View More Examples of update(PreparedStatementCreator psc,KeyHolder generatedKeyHolder)
   1: 
   2: import org.springframework.jdbc.core.JdbcTemplate;
   3: import org.springframework.jdbc.core.RowMapper;
   4:         ...
   5: 
   6:         JdbcTemplate jt = getJdbcTemplate();
   7: 
   8:         ...
   9: 
  10:         jt.update(INSERT_PIXUSER_SQL, userParameters);
  11: 
  12:         ...
  13:         };
  14:         jt.update(INSERT_ALBUM_SQL, movieParameters);

View Full Code Here
   1: 
   2:     private JdbcTemplate jdbcTemplate;
   3: 
   4:         ...
   5:     public BoxOfficeDBHelper(JdbcTemplate jdbcTemplate) {
   6:         this.jdbcTemplate = jdbcTemplate;
   7:         ...
   8:         Object[] args = new Object[] { new Long(id), name };
   9:         jdbcTemplate.update(sql, args);
  10:     }
  11:         ...
  12:         };
  13:         jdbcTemplate.update(sql, args);

View Full Code Here