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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|