Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public DatabaseManager() {
- p.setUrl(url);
- p.setDriverClassName("org.postgresql.Driver");
- p.setUrl(user);
- p.setPassword(password);
- p.setJmxEnabled(true);
- p.setTestWhileIdle(false);
- p.setTestOnBorrow(true);
- p.setValidationQuery("SELECT 1");
- p.setTestOnReturn(false);
- p.setValidationInterval(30000);
- p.setTimeBetweenEvictionRunsMillis(30000);
- p.setMaxActive(100);
- p.setInitialSize(10);
- p.setMaxWait(10000);
- p.setRemoveAbandonedTimeout(60);
- p.setMinEvictableIdleTimeMillis(30000);
- p.setMinIdle(10);
- p.setLogAbandoned(true);
- p.setRemoveAbandoned(true);
- p.setJdbcInterceptors(
- "org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"+
- "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");
- datasource.setPoolProperties(p);
- }
- public Connection getConnection() throws SQLException {
- con = datasource.getConnection();
- return con;
- }
- public void close(Connection c) {
- con = c;
- try {
- con.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
- http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
- version="2.4">
- <description>My Cool App</description>
- <resource-ref>
- <description>Cool Data Source</description>
- <res-ref-name>jdbc/postgres</res-ref-name>
- <res-type>javax.sql.DataSource</res-type>
- <res-auth>Container</res-auth>
- </resource-ref>
- </web-app>
- <Context>
- <!-- Default set of monitored resources -->
- <WatchedResource>WEB-INF/web.xml</WatchedResource>
- <!-- Uncomment this to disable session persistence across Tomcat restarts -->
- <Manager pathname="" />
- <!-- Uncomment this to enable Comet connection tacking (provides events
- on session expiration as well as webapp lifecycle) -->
- <!--
- <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
- -->
- <Resource name="jdbc/postgres" auth="Container"
- type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
- url="jdbc:postgresql://127.0.0.1:5432/cooldb"
- username="cooluser" password="coolerpass" maxActive="20" maxIdle="10"
- maxWait="-1"/>
- <ResourceLink global="jdbc/postgres" name="jdbc/postgres" type="javax.sql.DataSource"/>
- </Context>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement