Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. public DatabaseManager() {
  2. p.setUrl(url);
  3. p.setDriverClassName("org.postgresql.Driver");
  4. p.setUrl(user);
  5. p.setPassword(password);
  6. p.setJmxEnabled(true);
  7. p.setTestWhileIdle(false);
  8. p.setTestOnBorrow(true);
  9. p.setValidationQuery("SELECT 1");
  10. p.setTestOnReturn(false);
  11. p.setValidationInterval(30000);
  12. p.setTimeBetweenEvictionRunsMillis(30000);
  13. p.setMaxActive(100);
  14. p.setInitialSize(10);
  15. p.setMaxWait(10000);
  16. p.setRemoveAbandonedTimeout(60);
  17. p.setMinEvictableIdleTimeMillis(30000);
  18. p.setMinIdle(10);
  19. p.setLogAbandoned(true);
  20. p.setRemoveAbandoned(true);
  21. p.setJdbcInterceptors(
  22. "org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"+
  23. "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");
  24. datasource.setPoolProperties(p);
  25. }
  26.  
  27. public Connection getConnection() throws SQLException {
  28.  
  29. con = datasource.getConnection();
  30. return con;
  31. }
  32.  
  33. public void close(Connection c) {
  34. con = c;
  35. try {
  36. con.close();
  37. } catch (SQLException e) {
  38. // TODO Auto-generated catch block
  39. e.printStackTrace();
  40. }
  41. }
  42.  
  43. <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
  44. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  45. xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
  46. http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
  47. version="2.4">
  48. <description>My Cool App</description>
  49. <resource-ref>
  50. <description>Cool Data Source</description>
  51. <res-ref-name>jdbc/postgres</res-ref-name>
  52. <res-type>javax.sql.DataSource</res-type>
  53. <res-auth>Container</res-auth>
  54. </resource-ref>
  55. </web-app>
  56.  
  57. <Context>
  58.  
  59. <!-- Default set of monitored resources -->
  60. <WatchedResource>WEB-INF/web.xml</WatchedResource>
  61.  
  62. <!-- Uncomment this to disable session persistence across Tomcat restarts -->
  63.  
  64. <Manager pathname="" />
  65.  
  66.  
  67. <!-- Uncomment this to enable Comet connection tacking (provides events
  68. on session expiration as well as webapp lifecycle) -->
  69. <!--
  70. <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
  71. -->
  72.  
  73. <Resource name="jdbc/postgres" auth="Container"
  74. type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
  75. url="jdbc:postgresql://127.0.0.1:5432/cooldb"
  76. username="cooluser" password="coolerpass" maxActive="20" maxIdle="10"
  77. maxWait="-1"/>
  78. <ResourceLink global="jdbc/postgres" name="jdbc/postgres" type="javax.sql.DataSource"/>
  79.  
  80.  
  81. </Context>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement