Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DataSource dataSource = null;
- try
- {
- InitialContext ctx = new InitialContext();
- // comp/env is for component-environment bindings, such as web application bindings
- // this allows us to change the name later in the binding (in the ibm-web-bnd.xml file), instead of here in the code.
- dataSource = (DataSource) ctx.lookup("java:comp/env/jdbc/refDB");
- }
- catch (NamingException e)
- {
- e.printStackTrace();
- }
- return dataSource.getConnection();
- System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory");
- System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming");
- InitialContext ctx = new InitialContext();
- //"java:comp/env/jdbc/CacheDb" is the context that needs creating here.
- ctx.createSubcontext("java:");
- ctx.createSubcontext("java:comp");
- ctx.createSubcontext("java:comp/env");
- ctx.createSubcontext("java:comp/env/jdbc");
- JdbcDataSource dataSource = new JdbcDataSource();
- dataSource.setURL("jdbc:h2:mem:cachedb;DB_CLOSE_DELAY=-1"); // don't delete the database when the last connection closes
- ctx.bind("java:comp/env/jdbc/CacheDb", dataSource);
- System.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
- System.setProperty(Context.URL_PKG_PREFIXES, "com.ibm.websphere.naming");
Add Comment
Please, Sign In to add comment