Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <GlobalNamingResources>
- <Resource auth="Container" driverClassName="org.postgresql.Driver" maxIdle="30" maxTotal="100" maxWaitMillis="10000" name="jdbc/dsTriasEmployees" password="pwd" type="javax.sql.DataSource" url="jdbc:postgresql://localhost:5432/trias_employees" username="login"/>
- </GlobalNamingResources>
- <ResourceLink name="jdbc/dsTriasEmployees" global="jdbc/dsTriasEmployees"
- type="javax.sql.DataSource" />
- DataSource datasource;
- public Connection connectJNDI() {
- try {
- Context initContext = new InitialContext();
- Context envContext = (Context) initContext.lookup("java:/comp/env");
- datasource = (DataSource) envContext.lookup("jdbc/trias_employees");
- Connection con = datasource.getConnection();
- genericLogger.info("JNDI LOOKUP -> " + con);
- return con;
- } catch (Exception ex) {
- genericLogger.error("JNDI LOOKUP -> " + ex);
- return null;
- }
- javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
- <resource-ref>
- <description>
- DB PostgreSQL
- </description>
- <res-ref-name>
- jdbc/trias_employees
- </res-ref-name>
- <res-type>
- javax.sql.DataSource
- </res-type>
- <res-auth>
- Container
- </res-auth>
- </resource-ref>
- TomcatJNDI tomcatJNDI = new TomcatJNDI();
- tomcatJNDI.processServerXml(File serverXml)
- tomcatJNDI.processContextXml(contextXmlFile);
- tomcatJNDI.start();
- DataSource ds = (DataSource) InitialContext.doLookup("java:comp/env/jdbc/trias_employee")
Add Comment
Please, Sign In to add comment