spring-framework / org.springframework.jdbc.support

Package org.springframework.jdbc.support

Types

CustomSQLErrorCodesTranslation

open class CustomSQLErrorCodesTranslation

JavaBean for holding custom JDBC error codes translation for a particular database. The "exceptionClass" property defines which exception will be thrown for the list of error codes specified in the errorCodes property.

CustomSQLExceptionTranslatorRegistrar

open class CustomSQLExceptionTranslatorRegistrar : InitializingBean

Registry for registering custom org.springframework.jdbc.support.SQLExceptionTranslator instances for specific databases.

CustomSQLExceptionTranslatorRegistry

open class CustomSQLExceptionTranslatorRegistry

Registry for custom org.springframework.jdbc.support.SQLExceptionTranslator instances associated with specific databases allowing for overriding translation based on values contained in the configuration file named "sql-error-codes.xml".

DatabaseStartupValidator

open class DatabaseStartupValidator : InitializingBean

Bean that checks if a database has already started up. To be referenced via "depends-on" from beans that depend on database startup, like a Hibernate SessionFactory or custom data access objects that access a DataSource directly.

Useful to defer application initialization until a database has started up. Particularly appropriate for waiting on a slowly starting Oracle database.

GeneratedKeyHolder

open class GeneratedKeyHolder : KeyHolder

Default implementation of the KeyHolder interface, to be used for holding auto-generated keys (as potentially returned by JDBC insert statements).

Create an instance of this class for each insert operation, and pass it to the corresponding org.springframework.jdbc.core.JdbcTemplate or {org.springframework.jdbc.object.SqlUpdate} methods.

JdbcAccessor

abstract class JdbcAccessor : InitializingBean

Base class for org.springframework.jdbc.core.JdbcTemplate and other JDBC-accessing DAO helpers, defining common properties such as DataSource and exception translator.

Not intended to be used directly. See org.springframework.jdbc.core.JdbcTemplate.

JdbcUtils

abstract class JdbcUtils

Generic utility methods for working with JDBC. Mainly for internal use within the framework, but also useful for custom JDBC access code.

SQLErrorCodeSQLExceptionTranslator

open class SQLErrorCodeSQLExceptionTranslator : AbstractFallbackSQLExceptionTranslator

Implementation of SQLExceptionTranslator that analyzes vendor-specific error codes. More precise than an implementation based on SQL state, but heavily vendor-specific.

This class applies the following matching rules:

  • Try custom translation implemented by any subclass. Note that this class is concrete and is typically used itself, in which case this rule doesn't apply.
  • Apply error code matching. Error codes are obtained from the SQLErrorCodesFactory by default. This factory loads a "sql-error-codes.xml" file from the class path, defining error code mappings for database names from database metadata.
  • Fallback to a fallback translator. SQLStateSQLExceptionTranslator is the default fallback translator, analyzing the exception's SQL state only. On Java 6 which introduces its own SQLException subclass hierarchy, we will use SQLExceptionSubclassTranslator by default, which in turns falls back to Spring's own SQL state translation when not encountering specific subclasses.

The configuration file named "sql-error-codes.xml" is by default read from this package. It can be overridden through a file of the same name in the root of the class path (e.g. in the "/WEB-INF/classes" directory), as long as the Spring JDBC package is loaded from the same ClassLoader.

SQLExceptionSubclassTranslator

open class SQLExceptionSubclassTranslator : AbstractFallbackSQLExceptionTranslator

SQLExceptionTranslator implementation which analyzes the specific java.sql.SQLException subclass thrown by the JDBC driver.

Falls back to a standard SQLStateSQLExceptionTranslator if the JDBC driver does not actually expose JDBC 4 compliant SQLException subclasses.

SQLExceptionTranslator

interface SQLExceptionTranslator

Strategy interface for translating between SQLException and Spring's data access strategy-agnostic DataAccessException hierarchy.

Implementations can be generic (for example, using SQLState codes for JDBC) or wholly proprietary (for example, using Oracle error codes) for greater precision.

SQLStateSQLExceptionTranslator

open class SQLStateSQLExceptionTranslator : AbstractFallbackSQLExceptionTranslator

SQLExceptionTranslator implementation that analyzes the SQL state in the SQLException based on the first two digits (the SQL state "class"). Detects standard SQL state values and well-known vendor-specific SQL states.

Not able to diagnose all problems, but is portable between databases and does not require special initialization (no database vendor detection, etc.). For more precise translation, consider SQLErrorCodeSQLExceptionTranslator.

SqlValue

interface SqlValue

Simple interface for complex types to be set as statement parameters.

Implementations perform the actual work of setting the actual values. They must implement the callback method setValue which can throw SQLExceptions that will be caught and translated by the calling code. This callback method has access to the underlying Connection via the given PreparedStatement object, if that should be needed to create any database-specific objects.

Exceptions

MetaDataAccessException

open class MetaDataAccessException : NestedCheckedException

Exception indicating that something went wrong during JDBC metadata lookup.

This is a checked exception since we want it to be caught, logged and handled rather than cause the application to fail. Failure to read JDBC metadata is usually not a fatal problem.