Guest User

Untitled

a guest
Nov 16th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. <GlobalNamingResources>
  2. <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"/>
  3. </GlobalNamingResources>
  4.  
  5. <ResourceLink name="jdbc/dsTriasEmployees" global="jdbc/dsTriasEmployees"
  6. type="javax.sql.DataSource" />
  7.  
  8. DataSource datasource;
  9.  
  10. public Connection connectJNDI() {
  11. try {
  12. Context initContext = new InitialContext();
  13. Context envContext = (Context) initContext.lookup("java:/comp/env");
  14. datasource = (DataSource) envContext.lookup("jdbc/trias_employees");
  15. Connection con = datasource.getConnection();
  16. genericLogger.info("JNDI LOOKUP -> " + con);
  17. return con;
  18. } catch (Exception ex) {
  19. genericLogger.error("JNDI LOOKUP -> " + ex);
  20.  
  21. return null;
  22. }
  23.  
  24. 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
  25.  
  26. <resource-ref>
  27. <description>
  28. DB PostgreSQL
  29. </description>
  30. <res-ref-name>
  31. jdbc/trias_employees
  32. </res-ref-name>
  33. <res-type>
  34. javax.sql.DataSource
  35. </res-type>
  36. <res-auth>
  37. Container
  38. </res-auth>
  39. </resource-ref>
  40.  
  41. TomcatJNDI tomcatJNDI = new TomcatJNDI();
  42. tomcatJNDI.processServerXml(File serverXml)
  43. tomcatJNDI.processContextXml(contextXmlFile);
  44. tomcatJNDI.start();
  45.  
  46. DataSource ds = (DataSource) InitialContext.doLookup("java:comp/env/jdbc/trias_employee")
Add Comment
Please, Sign In to add comment