public abstract class

SimpleJdbcTestUtils

extends Object
java.lang.Object
   ↳ org.springframework.test.jdbc.SimpleJdbcTestUtils

Class Overview

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

Summary

Public Constructors
SimpleJdbcTestUtils()
Public Methods
static int countRowsInTable(SimpleJdbcTemplate simpleJdbcTemplate, String tableName)
Count the rows in the given table.
static int deleteFromTables(SimpleJdbcTemplate simpleJdbcTemplate, String... tableNames)
Delete all rows from the specified tables.
static void executeSqlScript(SimpleJdbcTemplate simpleJdbcTemplate, Resource resource, boolean continueOnError)
Execute the given SQL script.
static void executeSqlScript(SimpleJdbcTemplate simpleJdbcTemplate, EncodedResource resource, boolean continueOnError)
Execute the given SQL script.
static void executeSqlScript(SimpleJdbcTemplate simpleJdbcTemplate, ResourceLoader resourceLoader, String sqlResourcePath, boolean continueOnError)
Execute the given SQL script.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public SimpleJdbcTestUtils ()

Public Methods

public static 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

public static int deleteFromTables (SimpleJdbcTemplate simpleJdbcTemplate, String... tableNames)

Delete 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

public static void executeSqlScript (SimpleJdbcTemplate simpleJdbcTemplate, Resource resource, boolean continueOnError)

Execute the given SQL script. The script will normally be loaded by classpath.

Statements should be delimited with a semicolon. If statements are not delimited with a semicolon then there should be one statement per line. Statements are allowed to span lines only if they are delimited with a semicolon.

Do not use this method to execute DDL if you expect rollback.

Parameters
simpleJdbcTemplate the SimpleJdbcTemplate with which to perform JDBC operations
resource the resource to load the SQL script from.
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

public static void executeSqlScript (SimpleJdbcTemplate simpleJdbcTemplate, EncodedResource resource, boolean continueOnError)

Execute the given SQL script.

The script will 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.

Parameters
simpleJdbcTemplate the SimpleJdbcTemplate with which to perform JDBC operations
resource the resource (potentially associated with a specific encoding) to load the SQL script from.
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

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

Execute the given SQL script.

The script will 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.

Parameters
simpleJdbcTemplate the SimpleJdbcTemplate with which to perform JDBC operations
resourceLoader the resource loader (with which to load the SQL script
sqlResourcePath the Spring resource path for the SQL script
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