JdbcDataSourceA 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.
Connection getConnection() throws SQLExceptionOpen a new connection using the current URL, user name and password.Returns:
the connection
Connection getConnection(String user, String password) throws SQLExceptionOpen a new connection using the current URL and the specified user name and password.Parameters:
user - the user name
password - the password
Returns:
the connection
PrintWriter getLogWriter()Get the current log writer for this object.Returns:
the log writer
int getLoginTimeout()Get the login timeout in seconds, 0 meaning no timeout.Returns:
the timeout in seconds
String getPassword()Get the current password.Returns:
the password
PooledConnection getPooledConnection() throws SQLExceptionOpen a new pooled connection using the current URL, user name and password.Returns:
the connection
PooledConnection getPooledConnection(String user, String password) throws SQLExceptionOpen a new pooled connection using the current URL and the specified user name and password.Parameters:
user - the user name
password - the password
Returns:
the connection
Reference getReference()Get a new reference for this object, using the current settings.Returns:
the new reference
String getURL()Get the current URL.Returns:
the URL
String getUser()Get the current user name.Returns:
the user name
XAConnection getXAConnection() throws SQLExceptionOpen a new XA connection using the current URL, user name and password.Returns:
the connection
XAConnection getXAConnection(String user, String password) throws SQLExceptionOpen a new XA connection using the current URL and the specified user name and password.Parameters:
user - the user name
password - the password
Returns:
the connection
void setLogWriter(PrintWriter out)Set the current log writer for this object. This value is ignored by this database.Parameters:
out - the log writer
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.Parameters:
timeout - the timeout in seconds
void setPassword(String password)Set the current passwordParameters:
password - the new password.
void setURL(String url)Set the current URL.Parameters:
url - the new URL
void setUser(String user)Set the current user name.Parameters:
user - the new user name
|