For the latest stable version, please use Spring Framework 6.2.0!spring-doc.cn

JDBC Testing Support

JdbcTestUtils

The org.springframework.test.jdbc package contains JdbcTestUtils, which is a collection of JDBC-related utility functions intended to simplify standard database testing scenarios. Specifically, JdbcTestUtils provides the following static utility methods.spring-doc.cn

  • countRowsInTable(..): Counts the number of rows in the given table.spring-doc.cn

  • countRowsInTableWhere(..): Counts the number of rows in the given table by using the provided WHERE clause.spring-doc.cn

  • deleteFromTables(..): Deletes all rows from the specified tables.spring-doc.cn

  • deleteFromTableWhere(..): Deletes rows from the given table by using the provided WHERE clause.spring-doc.cn

  • dropTables(..): Drops the specified tables.spring-doc.cn

AbstractTransactionalJUnit4SpringContextTests and AbstractTransactionalTestNGSpringContextTests provide convenience methods that delegate to the aforementioned methods in JdbcTestUtils.spring-doc.cn

Embedded Databases

The spring-jdbc module provides support for configuring and launching an embedded database, which you can use in integration tests that interact with a database. For details, see Embedded Database Support and Testing Data Access Logic with an Embedded Database.spring-doc.cn