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.
| Modifier and Type | Field and Description |
|---|---|
| private String | |
| private transient JdbcDataSourceFactory | |
| private int | |
| private transient PrintWriter | |
| private char[] | |
| private static final long | |
| private String | |
| private String |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private static String | |
| public Connection | Returns: the connectionImplements javax. Open a new connection using the current URL, user name and password. |
| public Connection | Returns: the connectionthe user name user, String the password password)Implements javax. Open a new connection using the current URL and the specified user name and password. |
| public String | |
| public int | Returns: the timeout in secondsImplements javax. Get the login timeout in seconds, 0 meaning no timeout. |
| public PrintWriter | Returns: the log writerImplements javax. Get the current log writer for this object. |
| public java. | |
| public String | |
| public PooledConnection | Returns: the connectionImplements javax. Open a new pooled connection using the current URL, user name and password. |
| public PooledConnection | Returns: the connectionthe user name user, String the password password)Implements javax. Open a new pooled connection using the current URL and the specified user name and password. |
| public Reference | Returns: the new referenceImplements javax. Get a new reference for this object, using the current settings. |
| public String | |
| public String | |
| public String | |
| public XAConnection | Returns: the connectionImplements javax. Open a new XA connection using the current URL, user name and password. |
| public XAConnection | Returns: the connectionthe user name user, String the password password)Implements javax. 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 classthe class iface)Implements java. Checks if unwrap can return an object of this class. |
| private void | |
| public void | |
| public void | setLoginTimeout(int
the timeout in seconds timeout)Implements javax. Set the login timeout in seconds, 0 meaning no timeout. |
| public void | setLogWriter(PrintWriter
the log writer out)Implements javax. Set the current log writer for this object. |
| public void | |
| 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 | |
| public void | |
| public void | |
| public String | |
| public <T> T | Returns: thisthe class iface)Implements java. Return an object of this class if possible. |
| description | back to summary |
|---|---|
| private String description | |
| factory | back to summary |
|---|---|
| private transient JdbcDataSourceFactory factory | |
| loginTimeout | back to summary |
|---|---|
| private int loginTimeout | |
| logWriter | back to summary |
|---|---|
| private transient PrintWriter logWriter | |
| passwordChars | back to summary |
|---|---|
| private char[] passwordChars | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| url | back to summary |
|---|---|
| private String url | |
| userName | back to summary |
|---|---|
| private String userName | |
| JdbcDataSource | back to summary |
|---|---|
| public JdbcDataSource() The public constructor. | |
| convertToString | back to summary |
|---|---|
| private static String convertToString(char[] a) | |
| getConnection | back to summary |
|---|---|
| public Connection getConnection() throws SQLException Implements javax. Open a new connection using the current URL, user name and password.
| |
| getConnection | back to summary |
|---|---|
| public Connection getConnection(String user, String password) throws SQLException Implements javax. Open a new connection using the current URL and the specified user name and password.
| |
| getDescription | back to summary |
|---|---|
| public String getDescription() Get the current description.
| |
| getLoginTimeout | back to summary |
|---|---|
| public int getLoginTimeout() Implements javax. Get the login timeout in seconds, 0 meaning no timeout.
| |
| getLogWriter | back to summary |
|---|---|
| public PrintWriter getLogWriter() Implements javax. Get the current log writer for this object.
| |
| getParentLogger | back to summary |
|---|---|
| public java. Implements javax. [Not supported]
| |
| getPassword | back to summary |
|---|---|
| public String getPassword() Get the current password.
| |
| getPooledConnection | back to summary |
|---|---|
| public PooledConnection getPooledConnection() throws SQLException Implements javax. Open a new pooled connection using the current URL, user name and password.
| |
| getPooledConnection | back to summary |
|---|---|
| public PooledConnection getPooledConnection(String user, String password) throws SQLException Implements javax. Open a new pooled connection using the current URL and the specified user name and password.
| |
| getReference | back to summary |
|---|---|
| public Reference getReference() Implements javax. Get a new reference for this object, using the current settings. | |
| getURL | back to summary |
|---|---|
| public String getURL() Get the current URL.
| |
| getUrl | back 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.
| |
| getUser | back to summary |
|---|---|
| public String getUser() Get the current user name.
| |
| getXAConnection | back to summary |
|---|---|
| public XAConnection getXAConnection() throws SQLException Implements javax. Open a new XA connection using the current URL, user name and password.
| |
| getXAConnection | back to summary |
|---|---|
| public XAConnection getXAConnection(String user, String password) throws SQLException Implements javax. Open a new XA connection using the current URL and the specified user name and password.
| |
| initFactory | back to summary |
|---|---|
| private void initFactory() | |
| isWrapperFor | back to summary |
|---|---|
| public boolean isWrapperFor(Class<?> iface) throws SQLException Implements java. Checks if unwrap can return an object of this class.
| |
| readObject | back to summary |
|---|---|
| private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException Called when de-serializing the object.
| |
| setDescription | back to summary |
|---|---|
| public void setDescription(String description) Set the description.
| |
| setLoginTimeout | back to summary |
|---|---|
| public void setLoginTimeout(int timeout) Implements javax. Set the login timeout in seconds, 0 meaning no timeout. The default value is 0. This value is ignored by this database.
| |
| setLogWriter | back to summary |
|---|---|
| public void setLogWriter(PrintWriter out) Implements javax. Set the current log writer for this object. This value is ignored by this database.
| |
| setPassword | back to summary |
|---|---|
| public void setPassword(String password) Set the current password.
| |
| setPasswordChars | back to summary |
|---|---|
| public void setPasswordChars(char[] password) Set the current password in the form of a char array.
| |
| setURL | back to summary |
|---|---|
| public void setURL(String url) Set the current URL.
| |
| setUrl | back 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.
| |
| setUser | back to summary |
|---|---|
| public void setUser(String user) Set the current user name.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. INTERNAL
| |
| unwrap | back to summary |
|---|---|
| public <T> T unwrap(Class<T> iface) throws SQLException Implements java. Return an object of this class if possible.
| |