The Spring Framework

org.springframework.test.jdbc
Class SimpleJdbcTestUtils

java.lang.Object
  extended by org.springframework.test.jdbc.SimpleJdbcTestUtils

public abstract class SimpleJdbcTestUtils
extends Object

A Java-5-based collection of JDBC related utility functions intended to simplify standard database testing scenarios.

Since:
2.5
Author:
Sam Brannen, Juergen Hoeller

Constructor Summary
SimpleJdbcTestUtils()
           
 
Method Summary
static int countRowsInTable(SimpleJdbcTemplate simpleJdbcTemplate, String tableName)
          Count the rows in the given table.
static int deleteFromTables(SimpleJdbcTemplate simpleJdbcTemplate, String... tableNames)
          Deletes all rows from the specified tables.
static void executeSqlScript(SimpleJdbcTemplate simpleJdbcTemplate, ResourceLoader resourceLoader, String sqlResourcePath, boolean continueOnError)
           Execute the given SQL script.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleJdbcTestUtils

public SimpleJdbcTestUtils()
Method Detail

countRowsInTable

public static final int countRowsInTable(SimpleJdbcTemplate simpleJdbcTemplate,
                                         String tableName)
Count the rows in the given table.

Parameters:
simpleJdbcTemplate - The SimpleJdbcTemplate with which to perform JDBC operations.
tableName - table name to count rows in
Returns:
the number of rows in the table

deleteFromTables

public static final int deleteFromTables(SimpleJdbcTemplate simpleJdbcTemplate,
                                         String... tableNames)
Deletes all rows from the specified tables.

Parameters:
simpleJdbcTemplate - The SimpleJdbcTemplate with which to perform JDBC operations.
tableNames - The names of the tables from which to delete.
Returns:
The total number of rows deleted from all specified tables.

executeSqlScript

public static final void executeSqlScript(SimpleJdbcTemplate simpleJdbcTemplate,
                                          ResourceLoader resourceLoader,
                                          String sqlResourcePath,
                                          boolean continueOnError)
                                   throws DataAccessException

Execute the given SQL script.

Parameters:
simpleJdbcTemplate - The SimpleJdbcTemplate with which to perform JDBC operations.
resourceLoader - The resource loader (e.g., an ApplicationContextException) with which to load the SQL script.
sqlResourcePath - Spring resource path for the SQL script. Should normally be loaded by classpath. There should be one statement per line. Any semicolons will be removed. Do not use this method to execute DDL if you expect rollback.
continueOnError - whether or not to continue without throwing an exception in the event of an error.
Throws:
DataAccessException - if there is an error executing a statement and continueOnError was false.

The Spring Framework

Copyright © 2002-2007 The Spring Framework.