spring-framework / org.springframework.test.jdbc / JdbcTestUtils

JdbcTestUtils

open class JdbcTestUtils

JdbcTestUtils is a collection of JDBC related utility functions intended to simplify standard database testing scenarios.

Author
Thomas Risberg

Author
Sam Brannen

Author
Juergen Hoeller

Author
Phillip Webb

Author
Chris Baldwin

Since
2.5.4

See Also
org.springframework.jdbc.core.JdbcTemplateorg.springframework.jdbc.datasource.init.ScriptUtilsorg.springframework.jdbc.datasource.init.ResourceDatabasePopulatororg.springframework.jdbc.datasource.init.DatabasePopulatorUtils

Constructors

<init>

JdbcTestUtils()

JdbcTestUtils is a collection of JDBC related utility functions intended to simplify standard database testing scenarios.

Functions

countRowsInTable

open static fun countRowsInTable(jdbcTemplate: JdbcTemplate, tableName: String): Int

Count the rows in the given table.

countRowsInTableWhere

open static fun countRowsInTableWhere(jdbcTemplate: JdbcTemplate, tableName: String, whereClause: String): Int

Count the rows in the given table, using the provided WHERE clause.

If the provided WHERE clause contains text, it will be prefixed with " WHERE " and then appended to the generated SELECT statement. For example, if the provided table name is "person" and the provided where clause is "name = 'Bob' and age > 25", the resulting SQL statement to execute will be "SELECT COUNT(0) FROM person WHERE name = 'Bob' and age > 25".

deleteFromTableWhere

open static fun deleteFromTableWhere(jdbcTemplate: JdbcTemplate, tableName: String, whereClause: String, vararg args: Any): Int

Delete rows from the given table, using the provided WHERE clause.

If the provided WHERE clause contains text, it will be prefixed with " WHERE " and then appended to the generated DELETE statement. For example, if the provided table name is "person" and the provided where clause is "name = 'Bob' and age > 25", the resulting SQL statement to execute will be "DELETE FROM person WHERE name = 'Bob' and age > 25".

As an alternative to hard-coded values, the "?" placeholder can be used within the WHERE clause, binding to the given arguments.

deleteFromTables

open static fun deleteFromTables(jdbcTemplate: JdbcTemplate, vararg tableNames: String): Int

Delete all rows from the specified tables.

dropTables

open static fun dropTables(jdbcTemplate: JdbcTemplate, vararg tableNames: String): Unit

Drop the specified tables.