Package org.springframework.jdbc.support

# Class JdbcAccessor

java.lang.Object
org.springframework.jdbc.support.JdbcAccessor

All Implemented Interfaces:
  `org.springframework.beans.factory.InitializingBean`

Direct Known Subclasses:
  `JdbcTemplate`

public abstract class JdbcAccessor extends Object implements org.springframework.beans.factory.InitializingBean
Base class for `JdbcTemplate` and other JDBC-accessing DAO helpers, defining common properties such as DataSource and exception translator.

Not intended to be used directly. See `JdbcTemplate`.

Since:
  28.11.2003
Author:
  Juergen Hoeller, Sebastien Deleuze
See Also:
  - `JdbcTemplate`

## Field Summary

Fields
Modifier and Type
Field
Description
`protected final org.apache.commons.logging.Log`
`logger`
Logger available to subclasses.

## Constructor Summary

Constructors
Constructor
Description
`JdbcAccessor()`

## Method Summary

Modifier and Type
Method
Description
`void`
`afterPropertiesSet()`
Eagerly initialize the exception translator, if demanded, creating a default one for the specified DataSource if none set.
`DataSource`
`getDataSource()`
Return the DataSource used by this template.
`SQLExceptionTranslator`
`getExceptionTranslator()`
Return the exception translator to use for this instance, creating a default if necessary.
`boolean`
`isLazyInit()`
Return whether to lazily initialize the SQLExceptionTranslator for this accessor.
`protected DataSource`
`obtainDataSource()`
Obtain the DataSource for actual use.
`void`
`setDatabaseProductName(String dbName)`
Specify the database product name for the `DataSource` that this accessor uses.
`void`
`setDataSource(DataSource dataSource)`
Set the JDBC DataSource to obtain connections from.
`void`
`setExceptionTranslator(SQLExceptionTranslator exceptionTranslator)`
Set the exception translator for this instance.
`void`
`setLazyInit(boolean lazyInit)`
Set whether to lazily initialize the SQLExceptionTranslator for this accessor, on first encounter of an SQLException.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### logger

protected final org.apache.commons.logging.Log logger
Logger available to subclasses.

## Constructor Details

### JdbcAccessor

public JdbcAccessor()

## Method Details

### setDataSource

public void setDataSource(@Nullable DataSource dataSource)
Set the JDBC DataSource to obtain connections from.

### getDataSource

@Nullable public DataSource getDataSource()
Return the DataSource used by this template.

### obtainDataSource

protected DataSource obtainDataSource()
Obtain the DataSource for actual use.

Returns:
  the DataSource (never `null`)
Throws:
  `IllegalStateException` - in case of no DataSource set
Since:
  5.0

### setDatabaseProductName

public void setDatabaseProductName(String dbName)
Specify the database product name for the `DataSource` that this accessor uses. This allows for initializing a `SQLErrorCodeSQLExceptionTranslator` without obtaining a `Connection` from the `DataSource` to get the meta-data.

Parameters:
  `dbName` - the database product name that identifies the error codes entry
See Also:
  - `setExceptionTranslator(org.springframework.jdbc.support.SQLExceptionTranslator)`
  - `SQLErrorCodeSQLExceptionTranslator.setDatabaseProductName(java.lang.String)`
  - `DatabaseMetaData.getDatabaseProductName()`

### setExceptionTranslator

public void setExceptionTranslator(SQLExceptionTranslator exceptionTranslator)
Set the exception translator for this instance.

A `SQLErrorCodeSQLExceptionTranslator` used by default if a user-provided `sql-error-codes.xml` file has been found in the root of the classpath. Otherwise, `SQLExceptionSubclassTranslator` serves as the default translator as of 6.0.

See Also:
  - `SQLErrorCodeSQLExceptionTranslator`
  - `SQLExceptionSubclassTranslator`

### getExceptionTranslator

public SQLExceptionTranslator getExceptionTranslator()
Return the exception translator to use for this instance, creating a default if necessary.

See Also:
  - `setExceptionTranslator(org.springframework.jdbc.support.SQLExceptionTranslator)`

### setLazyInit

public void setLazyInit(boolean lazyInit)
Set whether to lazily initialize the SQLExceptionTranslator for this accessor, on first encounter of an SQLException. Default is "true"; can be switched to "false" for initialization on startup.

Early initialization just applies if `afterPropertiesSet()` is called.

See Also:
  - `getExceptionTranslator()`
  - `afterPropertiesSet()`

### isLazyInit

public boolean isLazyInit()
Return whether to lazily initialize the SQLExceptionTranslator for this accessor.

See Also:
  - `getExceptionTranslator()`

### afterPropertiesSet

public void afterPropertiesSet()
Eagerly initialize the exception translator, if demanded, creating a default one for the specified DataSource if none set.

Specified by:
  `afterPropertiesSet` in interface `org.springframework.beans.factory.InitializingBean`