Package org.h2.jdbcx
Class JdbcDataSource
java.lang.Object
org.h2.message.TraceObject
org.h2.jdbcx.JdbcDataSource
- All Implemented Interfaces:
Serializable
,Wrapper
,Referenceable
,CommonDataSource
,ConnectionPoolDataSource
,DataSource
,XADataSource
,JdbcDataSourceBackwardsCompat
public final class JdbcDataSource
extends org.h2.message.TraceObject
implements XADataSource, DataSource, ConnectionPoolDataSource, Serializable, Referenceable, JdbcDataSourceBackwardsCompat
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.
- See Also:
-
Field Summary
Fields inherited from class org.h2.message.TraceObject
ARRAY, BLOB, CALLABLE_STATEMENT, CLOB, CONNECTION, DATA_SOURCE, DATABASE_META_DATA, PARAMETER_META_DATA, PREPARED_STATEMENT, RESULT_SET, RESULT_SET_META_DATA, SAVEPOINT, SQLXML, STATEMENT, trace, XA_DATA_SOURCE, XID
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionOpen a new connection using the current URL, user name and password.getConnection
(String user, String password) Open a new connection using the current URL and the specified user name and password.Get the current description.int
Get the login timeout in seconds, 0 meaning no timeout.Get the current log writer for this object.[Not supported]Get the current password.Open a new pooled connection using the current URL, user name and password.getPooledConnection
(String user, String password) Open a new pooled connection using the current URL and the specified user name and password.Get a new reference for this object, using the current settings.getUrl()
Get the current URL.getURL()
Get the current URL.getUser()
Get the current user name.Open a new XA connection using the current URL, user name and password.getXAConnection
(String user, String password) Open a new XA connection using the current URL and the specified user name and password.boolean
isWrapperFor
(Class<?> iface) Checks if unwrap can return an object of this class.void
setDescription
(String description) Set the description.void
setLoginTimeout
(int timeout) Set the login timeout in seconds, 0 meaning no timeout.void
setLogWriter
(PrintWriter out) Set the current log writer for this object.void
setPassword
(String password) Set the current password.void
setPasswordChars
(char[] password) Set the current password in the form of a char array.void
Set the current URL.void
Set the current URL.void
Set the current user name.toString()
INTERNAL<T> T
Return an object of this class if possible.Methods inherited from class org.h2.message.TraceObject
debugCode, debugCodeAssign, debugCodeCall, debugCodeCall, debugCodeCall, getNextId, getTraceId, getTraceObjectName, isDebugEnabled, isInfoEnabled, logAndConvert, quote, quoteArray, quoteBigDecimal, quoteBytes, quoteDate, quoteIntArray, quoteMap, quoteTime, quoteTimestamp, setTrace, unsupported
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilder
Methods inherited from interface javax.sql.ConnectionPoolDataSource
createPooledConnectionBuilder
Methods inherited from interface javax.sql.DataSource
createConnectionBuilder
Methods inherited from interface javax.sql.XADataSource
createXAConnectionBuilder
-
Constructor Details
-
JdbcDataSource
public JdbcDataSource()The public constructor.
-
-
Method Details
-
getLoginTimeout
public int getLoginTimeout()Get the login timeout in seconds, 0 meaning no timeout.- Specified by:
getLoginTimeout
in interfaceCommonDataSource
- Specified by:
getLoginTimeout
in interfaceConnectionPoolDataSource
- Specified by:
getLoginTimeout
in interfaceDataSource
- Specified by:
getLoginTimeout
in interfaceXADataSource
- Returns:
- the timeout in seconds
-
setLoginTimeout
public void setLoginTimeout(int timeout) Set the login timeout in seconds, 0 meaning no timeout. The default value is 0. This value is ignored by this database.- Specified by:
setLoginTimeout
in interfaceCommonDataSource
- Specified by:
setLoginTimeout
in interfaceConnectionPoolDataSource
- Specified by:
setLoginTimeout
in interfaceDataSource
- Specified by:
setLoginTimeout
in interfaceXADataSource
- Parameters:
timeout
- the timeout in seconds
-
getLogWriter
Get the current log writer for this object.- Specified by:
getLogWriter
in interfaceCommonDataSource
- Specified by:
getLogWriter
in interfaceConnectionPoolDataSource
- Specified by:
getLogWriter
in interfaceDataSource
- Specified by:
getLogWriter
in interfaceXADataSource
- Returns:
- the log writer
-
setLogWriter
Set the current log writer for this object. This value is ignored by this database.- Specified by:
setLogWriter
in interfaceCommonDataSource
- Specified by:
setLogWriter
in interfaceConnectionPoolDataSource
- Specified by:
setLogWriter
in interfaceDataSource
- Specified by:
setLogWriter
in interfaceXADataSource
- Parameters:
out
- the log writer
-
getConnection
Open a new connection using the current URL, user name and password.- Specified by:
getConnection
in interfaceDataSource
- Returns:
- the connection
- Throws:
SQLException
-
getConnection
Open a new connection using the current URL and the specified user name and password.- Specified by:
getConnection
in interfaceDataSource
- Parameters:
user
- the user namepassword
- the password- Returns:
- the connection
- Throws:
SQLException
-
getURL
Get the current URL.- Returns:
- the URL
-
setURL
Set the current URL.- Parameters:
url
- the new URL
-
getUrl
Get the current URL. This method does the same as getURL, but this methods signature conforms the JavaBean naming convention.- Returns:
- the URL
-
setUrl
Set the current URL. This method does the same as setURL, but this methods signature conforms the JavaBean naming convention.- Parameters:
url
- the new URL
-
setPassword
Set the current password.- Parameters:
password
- the new password.
-
setPasswordChars
public void setPasswordChars(char[] password) Set the current password in the form of a char array.- Parameters:
password
- the new password in the form of a char array.
-
getPassword
Get the current password.- Returns:
- the password
-
getUser
Get the current user name.- Returns:
- the user name
-
setUser
Set the current user name.- Parameters:
user
- the new user name
-
getDescription
Get the current description.- Returns:
- the description
-
setDescription
Set the description.- Parameters:
description
- the new description
-
getReference
Get a new reference for this object, using the current settings.- Specified by:
getReference
in interfaceReferenceable
- Returns:
- the new reference
-
getXAConnection
Open a new XA connection using the current URL, user name and password.- Specified by:
getXAConnection
in interfaceXADataSource
- Returns:
- the connection
- Throws:
SQLException
-
getXAConnection
Open a new XA connection using the current URL and the specified user name and password.- Specified by:
getXAConnection
in interfaceXADataSource
- Parameters:
user
- the user namepassword
- the password- Returns:
- the connection
- Throws:
SQLException
-
getPooledConnection
Open a new pooled connection using the current URL, user name and password.- Specified by:
getPooledConnection
in interfaceConnectionPoolDataSource
- Returns:
- the connection
- Throws:
SQLException
-
getPooledConnection
Open a new pooled connection using the current URL and the specified user name and password.- Specified by:
getPooledConnection
in interfaceConnectionPoolDataSource
- Parameters:
user
- the user namepassword
- the password- Returns:
- the connection
- Throws:
SQLException
-
unwrap
Return an object of this class if possible.- Specified by:
unwrap
in interfaceWrapper
- Parameters:
iface
- the class- Returns:
- this
- Throws:
SQLException
-
isWrapperFor
Checks if unwrap can return an object of this class.- Specified by:
isWrapperFor
in interfaceWrapper
- Parameters:
iface
- the class- Returns:
- whether or not the interface is assignable from this class
- Throws:
SQLException
-
getParentLogger
[Not supported]- Specified by:
getParentLogger
in interfaceCommonDataSource
-
toString
INTERNAL
-