public class JdbcDataSource extends TraceObject implements XADataSource, DataSource, ConnectionPoolDataSource, Serializable, Referenceable, JdbcDataSourceBackwardsCompat
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.ARRAY, BLOB, CALLABLE_STATEMENT, CLOB, CONNECTION, DATA_SOURCE, DATABASE_META_DATA, PARAMETER_META_DATA, PREPARED_STATEMENT, RESULT_SET, RESULT_SET_META_DATA, SAVEPOINT, STATEMENT, trace, XA_DATA_SOURCE, XID| 构造器和说明 |
|---|
JdbcDataSource()
The public constructor.
|
| 限定符和类型 | 方法和说明 |
|---|---|
Connection |
getConnection()
Open a new connection using the current URL, user name and password.
|
Connection |
getConnection(String user,
String password)
Open a new connection using the current URL and the specified user name
and password.
|
String |
getDescription()
Get the current description.
|
int |
getLoginTimeout()
Get the login timeout in seconds, 0 meaning no timeout.
|
PrintWriter |
getLogWriter()
Get the current log writer for this object.
|
Logger |
getParentLogger()
[Not supported]
|
String |
getPassword()
Get the current password.
|
PooledConnection |
getPooledConnection()
Open a new pooled connection using the current URL, user name and
password.
|
PooledConnection |
getPooledConnection(String user,
String password)
Open a new pooled connection using the current URL and the specified user
name and password.
|
Reference |
getReference()
Get a new reference for this object, using the current settings.
|
String |
getUrl()
Get the current URL.
|
String |
getURL()
Get the current URL.
|
String |
getUser()
Get the current user name.
|
XAConnection |
getXAConnection()
Open a new XA connection using the current URL, user name and password.
|
XAConnection |
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)
[Not supported] 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 |
setUrl(String url)
Set the current URL.
|
void |
setURL(String url)
Set the current URL.
|
void |
setUser(String user)
Set the current user name.
|
String |
toString()
INTERNAL
|
<T> T |
unwrap(Class<T> iface)
[Not supported] Return an object of this class if possible.
|
debugCode, debugCodeAssign, debugCodeCall, debugCodeCall, debugCodeCall, getNextId, getTraceId, getTraceObjectName, isDebugEnabled, isInfoEnabled, logAndConvert, quote, quoteArray, quoteBigDecimal, quoteBytes, quoteDate, quoteIntArray, quoteMap, quoteTime, quoteTimestamp, setTrace, unsupportedpublic int getLoginTimeout()
getLoginTimeout 在接口中 CommonDataSourcepublic void setLoginTimeout(int timeout)
setLoginTimeout 在接口中 CommonDataSourcetimeout - the timeout in secondspublic PrintWriter getLogWriter()
getLogWriter 在接口中 CommonDataSourcepublic void setLogWriter(PrintWriter out)
setLogWriter 在接口中 CommonDataSourceout - the log writerpublic Connection getConnection() throws SQLException
getConnection 在接口中 DataSourceSQLExceptionpublic Connection getConnection(String user, String password) throws SQLException
getConnection 在接口中 DataSourceuser - the user namepassword - the passwordSQLExceptionpublic String getURL()
public void setURL(String url)
url - the new URLpublic String getUrl()
public void setUrl(String url)
url - the new URLpublic void setPassword(String password)
password - the new password.public void setPasswordChars(char[] password)
password - the new password in the form of a char array.public String getPassword()
public String getUser()
public void setUser(String user)
user - the new user namepublic String getDescription()
public void setDescription(String description)
description - the new descriptionpublic Reference getReference()
getReference 在接口中 Referenceablepublic XAConnection getXAConnection() throws SQLException
getXAConnection 在接口中 XADataSourceSQLExceptionpublic XAConnection getXAConnection(String user, String password) throws SQLException
getXAConnection 在接口中 XADataSourceuser - the user namepassword - the passwordSQLExceptionpublic PooledConnection getPooledConnection() throws SQLException
getPooledConnection 在接口中 ConnectionPoolDataSourceSQLExceptionpublic PooledConnection getPooledConnection(String user, String password) throws SQLException
getPooledConnection 在接口中 ConnectionPoolDataSourceuser - the user namepassword - the passwordSQLExceptionpublic <T> T unwrap(Class<T> iface) throws SQLException
unwrap 在接口中 Wrapperiface - the classSQLExceptionpublic boolean isWrapperFor(Class<?> iface) throws SQLException
isWrapperFor 在接口中 Wrapperiface - the classSQLExceptionpublic Logger getParentLogger()
getParentLogger 在接口中 CommonDataSourceCopyright © 2017. All rights reserved.