Package Hierarchy
-
core:JdbcTemplate 类,可在基本 JDBC 处理、错误处理和JDBC 批量操作中使用。
-
datasource:用于简化数据源访问和为测试和运行独立 JDBC 代码提供数据源实现的实用程序。
-
object:将 RDBMS 查询、更新和存储过程表示为线程安全、可重用对象的类。
-
support:提供 SQLException 转换功能和实用程序类,通过将 JDBC 异常转换为 org.springframework.dao 包中的异常,简化错误处理。
Spring 框架的 JDBC 抽象框架由以下四个不同的包组成:
The Spring Framework’s JDBC abstraction framework consists of four different packages:
-
core
:org.springframework.jdbc.core
包包含JdbcTemplate
类及其各种回调接口,以及各种相关的类。名为org.springframework.jdbc.core.simple
的子包包含SimpleJdbcInsert
和SimpleJdbcCall
类。另一个名为org.springframework.jdbc.core.namedparam
的子包包含NamedParameterJdbcTemplate
类和相关的支持类。请参阅 Using the JDBC Core Classes to Control Basic JDBC Processing and Error Handling、JDBC Batch Operations 和 Simplifying JDBC Operations with theSimpleJdbc
Classes。 -
core
: Theorg.springframework.jdbc.core
package contains theJdbcTemplate
class and its various callback interfaces, plus a variety of related classes. A subpackage namedorg.springframework.jdbc.core.simple
contains theSimpleJdbcInsert
andSimpleJdbcCall
classes. Another subpackage namedorg.springframework.jdbc.core.namedparam
contains theNamedParameterJdbcTemplate
class and the related support classes. See Using the JDBC Core Classes to Control Basic JDBC Processing and Error Handling, JDBC Batch Operations, and Simplifying JDBC Operations with theSimpleJdbc
Classes. -
datasource
:org.springframework.jdbc.datasource
包包含一个实用类,用于轻松DataSource
访问和各种简单的DataSource
实现,您可以使用它们在 Jakarta EE 容器之外测试和运行未修改的 JDBC 代码。名为org.springframework.jdbc.datasource.embedded
的子包提供了使用 Java 数据库引擎(如 HSQL、H2 和 Derby)创建嵌入式数据库的支持。请参阅 Controlling Database Connections 和 Embedded Database Support。 -
datasource
: Theorg.springframework.jdbc.datasource
package contains a utility class for easyDataSource
access and various simpleDataSource
implementations that you can use for testing and running unmodified JDBC code outside of a Jakarta EE container. A subpackage namedorg.springframework.jdbc.datasource.embedded
provides support for creating embedded databases by using Java database engines, such as HSQL, H2, and Derby. See Controlling Database Connections and Embedded Database Support. -
object
:org.springframework.jdbc.object
包包含表示 RDBMS 查询、更新和存储过程的类,这些类作为线程安全且可重用的对象。请参阅 Modeling JDBC Operations as Java Objects。这种样式会导致更面向对象的方法,虽然查询返回的对象自然与数据库断开连接。这种更高层次的 JDBC 抽象依赖于org.springframework.jdbc.core
包中的更低层次抽象。 -
object
: Theorg.springframework.jdbc.object
package contains classes that represent RDBMS queries, updates, and stored procedures as thread-safe, reusable objects. See Modeling JDBC Operations as Java Objects. This style results in a more object-oriented approach, although objects returned by queries are naturally disconnected from the database. This higher-level of JDBC abstraction depends on the lower-level abstraction in theorg.springframework.jdbc.core
package. -
support
:org.springframework.jdbc.support
包提供SQLException
转换功能以及一些实用类。在 JDBC 处理期间抛出的异常将转换为在org.springframework.dao
包中定义的异常。这意味着使用 Spring JDBC 抽象层的代码无需实现 JDBC 或 RDBMS 特定的错误处理。所有转换的异常都未选中,这为您提供了从可以恢复的异常中捕获异常,同时让其他异常传播到调用者的选项。请参阅 UsingSQLExceptionTranslator
。 -
support
: Theorg.springframework.jdbc.support
package providesSQLException
translation functionality and some utility classes. Exceptions thrown during JDBC processing are translated to exceptions defined in theorg.springframework.dao
package. This means that code using the Spring JDBC abstraction layer does not need to implement JDBC or RDBMS-specific error handling. All translated exceptions are unchecked, which gives you the option of catching the exceptions from which you can recover while letting other exceptions be propagated to the caller. See UsingSQLExceptionTranslator
.