Top Description Fields Constructors Methods
org.h2.jdbcx

public final Class JdbcDataSource

extends TraceObject
implements XADataSource, DataSource, ConnectionPoolDataSource, Serializable, Referenceable, JdbcDataSourceBackwardsCompat
Class Inheritance
All Implemented Interfaces
org.h2.jdbcx.JdbcDataSourceBackwardsCompat, javax.naming.Referenceable, java.io.Serializable, javax.sql.ConnectionPoolDataSource, javax.sql.CommonDataSource, javax.sql.DataSource, java.sql.Wrapper, javax.sql.XADataSource
Imports
java.io.IOException, .ObjectInputStream, .PrintWriter, .Serializable, java.sql.Connection, .SQLException, java.util.logging.Logger, javax.naming.Reference, .Referenceable, .StringRefAddr, javax.sql.ConnectionPoolDataSource, .DataSource, .PooledConnection, .XAConnection, .XADataSource, org.h2.jdbc.JdbcConnection, org.h2.message.DbException, .TraceObject, org.h2.util.StringUtils

A data source for H2 database connections. It is a factory for XAConnection and Connection objects. This class is usually registered in a JNDI naming service. To create a data source object and register it with a JNDI service, use the following code:
import org.h2.jdbcx.JdbcDataSource;
import javax.naming.Context;
import javax.naming.InitialContext;
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:˜/test");
ds.setUser("sa");
ds.setPassword("sa");
Context ctx = new InitialContext();
ctx.bind("jdbc/dsName", ds);
To use a data source that is already registered, use the following code:
import java.sql.Connection;
import javax.sql.DataSource;
import javax.naming.Context;
import javax.naming.InitialContext;
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("jdbc/dsName");
Connection conn = ds.getConnection();
In this example the user name and password are serialized as well; this may be a security problem in some cases.

Field Summary

Modifier and TypeField and Description
private String
private transient JdbcDataSourceFactory
private int
private transient PrintWriter
private char[]
private static final long
private String
private String
Inherited from org.h2.message.TraceObject:
ARRAYBLOBCALLABLE_STATEMENTCLOBCONNECTIONDATA_SOURCEDATABASE_META_DATAPARAMETER_META_DATAPREPARED_STATEMENTRESULT_SETRESULT_SET_META_DATASAVEPOINTSQLXMLSTATEMENTtraceXA_DATA_SOURCEXID

Constructor Summary

AccessConstructor and Description
public
JdbcDataSource()

The public constructor.

Method Summary

Modifier and TypeMethod and Description
private static String
convertToString(char[] a)

public Connection

Returns:

the connection
getConnection
()

Implements javax.sql.DataSource.getConnection.

Open a new connection using the current URL, user name and password.

public Connection

Returns:

the connection
getConnection
(String
the user name
user
,
String
the password
password
)

Implements javax.sql.DataSource.getConnection.

Open a new connection using the current URL and the specified user name and password.

public String

Returns:

the description
getDescription
()

Get the current description.

public int

Returns:

the timeout in seconds
getLoginTimeout
()

Implements javax.sql.XADataSource.getLoginTimeout, javax.sql.DataSource.getLoginTimeout, javax.sql.ConnectionPoolDataSource.getLoginTimeout.

Get the login timeout in seconds, 0 meaning no timeout.

public PrintWriter

Returns:

the log writer
getLogWriter
()

Implements javax.sql.XADataSource.getLogWriter, javax.sql.DataSource.getLogWriter, javax.sql.ConnectionPoolDataSource.getLogWriter.

Get the current log writer for this object.

public java.util.logging.Logger
public String

Returns:

the password
getPassword
()

Get the current password.

public PooledConnection

Returns:

the connection
getPooledConnection
()

Implements javax.sql.ConnectionPoolDataSource.getPooledConnection.

Open a new pooled connection using the current URL, user name and password.

public PooledConnection

Returns:

the connection
getPooledConnection
(String
the user name
user
,
String
the password
password
)

Implements javax.sql.ConnectionPoolDataSource.getPooledConnection.

Open a new pooled connection using the current URL and the specified user name and password.

public Reference

Returns:

the new reference
getReference
()

Implements javax.naming.Referenceable.getReference.

Get a new reference for this object, using the current settings.

public String

Returns:

the URL
getURL
()

Get the current URL.

public String

Returns:

the URL
getUrl
()

Get the current URL.

public String

Returns:

the user name
getUser
()

Get the current user name.

public XAConnection

Returns:

the connection
getXAConnection
()

Implements javax.sql.XADataSource.getXAConnection.

Open a new XA connection using the current URL, user name and password.

public XAConnection

Returns:

the connection
getXAConnection
(String
the user name
user
,
String
the password
password
)

Implements javax.sql.XADataSource.getXAConnection.

Open a new XA connection using the current URL and the specified user name and password.

private void
public boolean

Returns:

whether or not the interface is assignable from this class
isWrapperFor
(Class<?>
the class
iface
)

Implements java.sql.Wrapper.isWrapperFor.

Checks if unwrap can return an object of this class.

private void
readObject(ObjectInputStream
the input stream
in
)

Called when de-serializing the object.

public void
setDescription(String
the new description
description
)

Set the description.

public void
setLoginTimeout(int
the timeout in seconds
timeout
)

Implements javax.sql.XADataSource.setLoginTimeout, javax.sql.DataSource.setLoginTimeout, javax.sql.ConnectionPoolDataSource.setLoginTimeout.

Set the login timeout in seconds, 0 meaning no timeout.

public void
public void
setPassword(String
the new password.
password
)

Set the current password.

public void
setPasswordChars(char[]
the new password in the form of a char array.
password
)

Set the current password in the form of a char array.

public void
setURL(String
the new URL
url
)

Set the current URL.

public void
setUrl(String
the new URL
url
)

Set the current URL.

public void
setUser(String
the new user name
user
)

Set the current user name.

public String
toString()

Overrides java.lang.Object.toString.

INTERNAL

public <T> T

Returns:

this
unwrap
(Class<T>
the class
iface
)

Implements java.sql.Wrapper.unwrap.

Return an object of this class if possible.

Inherited from org.h2.message.TraceObject:
debugCodedebugCodeAssigndebugCodeCalldebugCodeCalldebugCodeCallgetNextIdgetTraceIdgetTraceObjectNameisDebugEnabledisInfoEnabledlogAndConvertquotequoteArrayquoteBigDecimalquoteBytesquoteDatequoteIntArrayquoteMapquoteTimequoteTimestampsetTraceunsupported

Field Detail

descriptionback to summary
private String description
factoryback to summary
private transient JdbcDataSourceFactory factory
loginTimeoutback to summary
private int loginTimeout
logWriterback to summary
private transient PrintWriter logWriter
passwordCharsback to summary
private char[] passwordChars
serialVersionUIDback to summary
private static final long serialVersionUID
urlback to summary
private String url
userNameback to summary
private String userName

Constructor Detail

JdbcDataSourceback to summary
public JdbcDataSource()

The public constructor.

Method Detail

convertToStringback to summary
private static String convertToString(char[] a)
getConnectionback to summary
public Connection getConnection() throws SQLException

Implements javax.sql.DataSource.getConnection.

Open a new connection using the current URL, user name and password.

Returns:Connection

the connection

Annotations
@Override
Exceptions
SQLException:

Doc from javax.sql.DataSource.getConnection.

if a database access error occurs

getConnectionback to summary
public Connection getConnection(String user, String password) throws SQLException

Implements javax.sql.DataSource.getConnection.

Open a new connection using the current URL and the specified user name and password.

Parameters
user:String

the user name

password:String

the password

Returns:Connection

the connection

Annotations
@Override
Exceptions
SQLException:

Doc from javax.sql.DataSource.getConnection.

if a database access error occurs

getDescriptionback to summary
public String getDescription()

Get the current description.

Returns:String

the description

getLoginTimeoutback to summary
public int getLoginTimeout()

Implements javax.sql.XADataSource.getLoginTimeout, javax.sql.DataSource.getLoginTimeout, javax.sql.ConnectionPoolDataSource.getLoginTimeout.

Get the login timeout in seconds, 0 meaning no timeout.

Returns:int

the timeout in seconds

Annotations
@Override
getLogWriterback to summary
public PrintWriter getLogWriter()

Implements javax.sql.XADataSource.getLogWriter, javax.sql.DataSource.getLogWriter, javax.sql.ConnectionPoolDataSource.getLogWriter.

Get the current log writer for this object.

Returns:PrintWriter

the log writer

Annotations
@Override
getParentLoggerback to summary
public java.util.logging.Logger getParentLogger()

Implements javax.sql.CommonDataSource.getParentLogger.

[Not supported]

Returns:java.util.logging.Logger

Doc from javax.sql.CommonDataSource.getParentLogger.

the parent Logger for this data source

Annotations
@Override
getPasswordback to summary
public String getPassword()

Get the current password.

Returns:String

the password

getPooledConnectionback to summary
public PooledConnection getPooledConnection() throws SQLException

Implements javax.sql.ConnectionPoolDataSource.getPooledConnection.

Open a new pooled connection using the current URL, user name and password.

Returns:PooledConnection

the connection

Annotations
@Override
Exceptions
SQLException:

Doc from javax.sql.ConnectionPoolDataSource.getPooledConnection.

if a database access error occurs

getPooledConnectionback to summary
public PooledConnection getPooledConnection(String user, String password) throws SQLException

Implements javax.sql.ConnectionPoolDataSource.getPooledConnection.

Open a new pooled connection using the current URL and the specified user name and password.

Parameters
user:String

the user name

password:String

the password

Returns:PooledConnection

the connection

Annotations
@Override
Exceptions
SQLException:

Doc from javax.sql.ConnectionPoolDataSource.getPooledConnection.

if a database access error occurs

getReferenceback to summary
public Reference getReference()

Implements javax.naming.Referenceable.getReference.

Get a new reference for this object, using the current settings.

Returns:Reference

the new reference

Annotations
@Override
getURLback to summary
public String getURL()

Get the current URL.

Returns:String

the URL

getUrlback to summary
public String getUrl()

Get the current URL. This method does the same as getURL, but this methods signature conforms the JavaBean naming convention.

Returns:String

the URL

getUserback to summary
public String getUser()

Get the current user name.

Returns:String

the user name

getXAConnectionback to summary
public XAConnection getXAConnection() throws SQLException

Implements javax.sql.XADataSource.getXAConnection.

Open a new XA connection using the current URL, user name and password.

Returns:XAConnection

the connection

Annotations
@Override
Exceptions
SQLException:

Doc from javax.sql.XADataSource.getXAConnection.

if a database access error occurs

getXAConnectionback to summary
public XAConnection getXAConnection(String user, String password) throws SQLException

Implements javax.sql.XADataSource.getXAConnection.

Open a new XA connection using the current URL and the specified user name and password.

Parameters
user:String

the user name

password:String

the password

Returns:XAConnection

the connection

Annotations
@Override
Exceptions
SQLException:

Doc from javax.sql.XADataSource.getXAConnection.

if a database access error occurs

initFactoryback to summary
private void initFactory()
isWrapperForback to summary
public boolean isWrapperFor(Class<?> iface) throws SQLException

Implements java.sql.Wrapper.isWrapperFor.

Checks if unwrap can return an object of this class.

Parameters
iface:Class<?>

the class

Returns:boolean

whether or not the interface is assignable from this class

Annotations
@Override
Exceptions
SQLException:

Doc from java.sql.Wrapper.isWrapperFor.

if an error occurs while determining whether this is a wrapper for an object with the given interface.

readObjectback to summary
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException

Called when de-serializing the object.

Parameters
in:ObjectInputStream

the input stream

Exceptions
IOException:
on failure
ClassNotFoundException:
on failure
setDescriptionback to summary
public void setDescription(String description)

Set the description.

Parameters
description:String

the new description

setLoginTimeoutback to summary
public void setLoginTimeout(int timeout)

Implements javax.sql.XADataSource.setLoginTimeout, javax.sql.DataSource.setLoginTimeout, javax.sql.ConnectionPoolDataSource.setLoginTimeout.

Set the login timeout in seconds, 0 meaning no timeout. The default value is 0. This value is ignored by this database.

Parameters
timeout:int

the timeout in seconds

Annotations
@Override
setLogWriterback to summary
public void setLogWriter(PrintWriter out)

Implements javax.sql.XADataSource.setLogWriter, javax.sql.DataSource.setLogWriter, javax.sql.ConnectionPoolDataSource.setLogWriter.

Set the current log writer for this object. This value is ignored by this database.

Parameters
out:PrintWriter

the log writer

Annotations
@Override
setPasswordback to summary
public void setPassword(String password)

Set the current password.

Parameters
password:String

the new password.

setPasswordCharsback to summary
public void setPasswordChars(char[] password)

Set the current password in the form of a char array.

Parameters
password:char[]

the new password in the form of a char array.

setURLback to summary
public void setURL(String url)

Set the current URL.

Parameters
url:String

the new URL

setUrlback to summary
public void setUrl(String url)

Set the current URL. This method does the same as setURL, but this methods signature conforms the JavaBean naming convention.

Parameters
url:String

the new URL

setUserback to summary
public void setUser(String user)

Set the current user name.

Parameters
user:String

the new user name

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

INTERNAL

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object

Annotations
@Override
unwrapback to summary
public <T> T unwrap(Class<T> iface) throws SQLException

Implements java.sql.Wrapper.unwrap.

Return an object of this class if possible.

Parameters
<T>

Doc from java.sql.Wrapper.unwrap. the type of the class modeled by this Class object

iface:Class<T>

the class

Returns:T

this

Annotations
@Override
@SuppressWarnings:unchecked
Exceptions
SQLException:

Doc from java.sql.Wrapper.unwrap.

If no object found that implements the interface