|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.h2.message.TraceObject
org.h2.jdbcx.JdbcDataSource
public class JdbcDataSource
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 |
---|
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, SQL_EXCEPTION, STATEMENT, trace, XA_DATA_SOURCE, XA_RESOURCE, XID |
Constructor Summary | |
---|---|
JdbcDataSource()
The public constructor. |
Method Summary | ||
---|---|---|
java.sql.Connection |
getConnection()
Open a new connection using the current URL, user name and password. |
|
java.sql.Connection |
getConnection(java.lang.String user,
java.lang.String password)
Open a new connection using the current URL and the specified user name and password. |
|
java.lang.String |
getDescription()
Get the current description. |
|
int |
getLoginTimeout()
Get the login timeout in seconds, 0 meaning no timeout. |
|
java.io.PrintWriter |
getLogWriter()
Get the current log writer for this object. |
|
java.lang.String |
getPassword()
Get the current password. |
|
javax.sql.PooledConnection |
getPooledConnection()
Open a new pooled connection using the current URL, user name and password. |
|
javax.sql.PooledConnection |
getPooledConnection(java.lang.String user,
java.lang.String password)
Open a new pooled connection using the current URL and the specified user name and password. |
|
javax.naming.Reference |
getReference()
Get a new reference for this object, using the current settings. |
|
java.lang.String |
getURL()
Get the current URL. |
|
java.lang.String |
getUser()
Get the current user name. |
|
javax.sql.XAConnection |
getXAConnection()
Open a new XA connection using the current URL, user name and password. |
|
javax.sql.XAConnection |
getXAConnection(java.lang.String user,
java.lang.String password)
Open a new XA connection using the current URL and the specified user name and password. |
|
boolean |
isWrapperFor(java.lang.Class<?> iface)
[Not supported] Checks if unwrap can return an object of this class. |
|
void |
setDescription(java.lang.String description)
Set the description. |
|
void |
setLoginTimeout(int timeout)
Set the login timeout in seconds, 0 meaning no timeout. |
|
void |
setLogWriter(java.io.PrintWriter out)
Set the current log writer for this object. |
|
void |
setPassword(java.lang.String password)
Set the current password. |
|
void |
setPasswordChars(char[] password)
Set the current password in the form of a char array. |
|
void |
setURL(java.lang.String url)
Set the current URL. |
|
void |
setUser(java.lang.String user)
Set the current user name. |
|
java.lang.String |
toString()
INTERNAL |
|
|
unwrap(java.lang.Class<T> iface)
[Not supported] Return an object of this class if possible. |
Methods inherited from class org.h2.message.TraceObject |
---|
debugCode, debugCodeAssign, debugCodeCall, debugCodeCall, debugCodeCall, getNextId, getTrace, 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 |
Constructor Detail |
---|
public JdbcDataSource()
Method Detail |
---|
public int getLoginTimeout()
getLoginTimeout
in interface javax.sql.CommonDataSource
public void setLoginTimeout(int timeout)
setLoginTimeout
in interface javax.sql.CommonDataSource
timeout
- the timeout in secondspublic java.io.PrintWriter getLogWriter()
getLogWriter
in interface javax.sql.CommonDataSource
public void setLogWriter(java.io.PrintWriter out)
setLogWriter
in interface javax.sql.CommonDataSource
out
- the log writerpublic java.sql.Connection getConnection() throws java.sql.SQLException
getConnection
in interface javax.sql.DataSource
java.sql.SQLException
public java.sql.Connection getConnection(java.lang.String user, java.lang.String password) throws java.sql.SQLException
getConnection
in interface javax.sql.DataSource
user
- the user namepassword
- the password
java.sql.SQLException
public java.lang.String getURL()
public void setURL(java.lang.String url)
url
- the new URLpublic void setPassword(java.lang.String password)
password
- the new password.public void setPasswordChars(char[] password)
password
- the new password in the form of a char array.public java.lang.String getPassword()
public java.lang.String getUser()
public void setUser(java.lang.String user)
user
- the new user namepublic java.lang.String getDescription()
public void setDescription(java.lang.String description)
description
- the new descriptionpublic javax.naming.Reference getReference()
getReference
in interface javax.naming.Referenceable
public javax.sql.XAConnection getXAConnection() throws java.sql.SQLException
getXAConnection
in interface javax.sql.XADataSource
java.sql.SQLException
public javax.sql.XAConnection getXAConnection(java.lang.String user, java.lang.String password) throws java.sql.SQLException
getXAConnection
in interface javax.sql.XADataSource
user
- the user namepassword
- the password
java.sql.SQLException
public javax.sql.PooledConnection getPooledConnection() throws java.sql.SQLException
getPooledConnection
in interface javax.sql.ConnectionPoolDataSource
java.sql.SQLException
public javax.sql.PooledConnection getPooledConnection(java.lang.String user, java.lang.String password) throws java.sql.SQLException
getPooledConnection
in interface javax.sql.ConnectionPoolDataSource
user
- the user namepassword
- the password
java.sql.SQLException
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException
unwrap
in interface java.sql.Wrapper
iface
- the class
java.sql.SQLException
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException
isWrapperFor
in interface java.sql.Wrapper
iface
- the class
java.sql.SQLException
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |