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
Constructors -
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.intGet 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.booleanisWrapperFor(Class<?> iface) Checks if unwrap can return an object of this class.voidsetDescription(String description) Set the description.voidsetLoginTimeout(int timeout) Set the login timeout in seconds, 0 meaning no timeout.voidsetLogWriter(PrintWriter out) Set the current log writer for this object.voidsetPassword(String password) Set the current password.voidsetPasswordChars(char[] password) Set the current password in the form of a char array.voidSet the current URL.voidSet the current URL.voidSet the current user name.toString()INTERNAL<T> TReturn 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, unsupportedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilderMethods inherited from interface javax.sql.ConnectionPoolDataSource
createPooledConnectionBuilderMethods inherited from interface javax.sql.DataSource
createConnectionBuilderMethods 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:
getLoginTimeoutin interfaceCommonDataSource- Specified by:
getLoginTimeoutin interfaceConnectionPoolDataSource- Specified by:
getLoginTimeoutin interfaceDataSource- Specified by:
getLoginTimeoutin 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:
setLoginTimeoutin interfaceCommonDataSource- Specified by:
setLoginTimeoutin interfaceConnectionPoolDataSource- Specified by:
setLoginTimeoutin interfaceDataSource- Specified by:
setLoginTimeoutin interfaceXADataSource- Parameters:
timeout- the timeout in seconds
-
getLogWriter
Get the current log writer for this object.- Specified by:
getLogWriterin interfaceCommonDataSource- Specified by:
getLogWriterin interfaceConnectionPoolDataSource- Specified by:
getLogWriterin interfaceDataSource- Specified by:
getLogWriterin interfaceXADataSource- Returns:
- the log writer
-
setLogWriter
Set the current log writer for this object. This value is ignored by this database.- Specified by:
setLogWriterin interfaceCommonDataSource- Specified by:
setLogWriterin interfaceConnectionPoolDataSource- Specified by:
setLogWriterin interfaceDataSource- Specified by:
setLogWriterin interfaceXADataSource- Parameters:
out- the log writer
-
getConnection
Open a new connection using the current URL, user name and password.- Specified by:
getConnectionin interfaceDataSource- Returns:
- the connection
- Throws:
SQLException
-
getConnection
Open a new connection using the current URL and the specified user name and password.- Specified by:
getConnectionin 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:
getReferencein interfaceReferenceable- Returns:
- the new reference
-
getXAConnection
Open a new XA connection using the current URL, user name and password.- Specified by:
getXAConnectionin 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:
getXAConnectionin 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:
getPooledConnectionin 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:
getPooledConnectionin interfaceConnectionPoolDataSource- Parameters:
user- the user namepassword- the password- Returns:
- the connection
- Throws:
SQLException
-
unwrap
Return an object of this class if possible.- Specified by:
unwrapin interfaceWrapper- Parameters:
iface- the class- Returns:
- this
- Throws:
SQLException
-
isWrapperFor
Checks if unwrap can return an object of this class.- Specified by:
isWrapperForin interfaceWrapper- Parameters:
iface- the class- Returns:
- whether or not the interface is assignable from this class
- Throws:
SQLException
-
getParentLogger
[Not supported]- Specified by:
getParentLoggerin interfaceCommonDataSource
-
toString
INTERNAL
-