# 3.1选择JDBC数据库访问方法

你可以选择几种方法来构成JDBC数据库访问的基础。除了JdbcTemplate的三种形式之外，新的SimpleJdbcInsert和SimpleJdbcCall方法还优化了数据库元数据，并且RDBMS Object样式采用了一种类似于JDO Query设计的面向对象的方法。一旦开始使用这些方法之一，你仍然可以混合搭配以包含来自其他方法的功能。所有方法都需要JDBC 2.0兼容的驱动程序，而某些高级功能需要JDBC 3.0驱动程序。

JdbcTemplate是经典且最流行的Spring JDBC方法。这种“最低级别”的方法以及其他所有方法都在后台使用了JdbcTemplate。

NamedParameterJdbcTemplate包装JdbcTemplate以提供命名参数而不是传统的JDBC？占位符。当你有多个SQL语句参数时，此方法可提供更好的文档编制和易用性。

SimpleJdbcInsert和SimpleJdbcCall优化数据库元数据以限制必要的配置量。这种方法简化了编码，因此你只需要提供表或过程的名称，并提供与列名称匹配的参数映射即可。仅当数据库提供足够的元数据时，此方法才有效。如果数据库不提供此元数据，则必须提供参数的显式配置。

RDBMS对象（包括MappingSqlQuery，SqlUpdate和StoredProcedure）要求你在数据访问层初始化期间创建可重用且线程安全的对象。此方法以JDO Query为模型，其中你定义查询字符串，声明参数并编译查询。完成后，可以使用各种参数值多次调用execute方法。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.flydean.com/spring-framework-documentation5/dataaccess/3.jdbc/3.1choosing-jdbc-database-access.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
