Advertisement
Guest User

Untitled

a guest
Jul 7th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. <resource-ref>
  2. <description>DB Connection</description>
  3. <res-ref-name>jdbc/myDatabaseName</res-ref-name>
  4. <res-type>javax.sql.DataSource</res-type>
  5. <res-auth>Container</res-auth>
  6. </resource-ref>
  7.  
  8. <ResourceLink type="javax.sql.DataSource"
  9. name="jdbc/localRemarket"
  10. global="jdbc/remarket"
  11. />
  12.  
  13. <Resource
  14. type="javax.sql.DataSource"
  15. name="jdbc/myDatabaseName"
  16. factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
  17. driverClassName="com.mysql.jdbc.Driver"
  18. url="jdbc:mysql://localhost:3306/myDatabaseName"
  19. username="myUsername"
  20. password="myPassword"
  21. maxActive="1500"
  22. maxIdle="200"
  23. maxwait="-1"
  24. testOnBorrow="true"
  25. testOnReturn="true"
  26. testWhileIdle="true"
  27. validationQuery="SELECT 1"
  28. timeBetweenEvictionRunsMillis="2000"
  29. minEvictableIdleTimeMillis="15000"
  30. removeAbandoned="true"
  31. removeAbandonedTimeout="5"
  32. />
  33.  
  34. <Resource
  35. type="javax.sql.DataSource"
  36. name="jdbc/myDatabaseName"
  37. factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
  38. driverClassName="com.mysql.jdbc.Driver"
  39. url="jdbc:mysql://localhost:3306/myDatabaseName"
  40. username="myUsername"
  41. password="myPassword"
  42. maxActive="1500"
  43. maxIdle="200"
  44. maxwait="-1"
  45. testOnBorrow="true"
  46. testOnReturn="true"
  47. testWhileIdle="true"
  48. validationQuery="SELECT 1"
  49. timeBetweenEvictionRunsMillis="2000"
  50. minEvictableIdleTimeMillis="15000"
  51. removeAbandoned="true"
  52. removeAbandonedTimeout="5"
  53. />
  54.  
  55. Connection conn;
  56.  
  57. public void openMyConnection() {
  58.  
  59. try {
  60.  
  61. Properties props = new Properties();
  62. props.put("java.naming.factory.initial", "org.apache.naming.java.javaURLContextFactory");
  63.  
  64. InitialContext ctx = new InitialContext(props);
  65. Context envCtx = (Context) ctx.lookup("java:comp/env"); // <<<<< PRB HERE
  66. // error message : Name [java:comp/env] is not bound in this Context. Unable to find [java:comp]
  67.  
  68. org.apache.tomcat.jdbc.pool.DataSource ds = (org.apache.tomcat.jdbc.pool.DataSource) envCtx.lookup("jdbc/localDB");
  69.  
  70. conn = ds.getConnection();
  71.  
  72. } catch (Exception e) {
  73. System.out.println(e.getMessage());
  74. }
  75.  
  76. }
  77.  
  78. props.put("java.naming.factory.initial", "org.apache.naming.java.javaURLContextFactory");
  79.  
  80. props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement