Tomcat connection pool, install jdbc driver for web application

I am building a web application with Tomcat 6 as a container and I am trying to use a connection pool. The jdbc driver I am using is jtds-1.2.2 .
The pool works fine when the driver box is placed under ${Catalina_Home}/lib, but my hosting provider did not let me do this.

I get a CNF exception when a driver is placed in WEB-INF/lib.

Can someone suggest a solution where I won’t have to go to tomcat installation?

+3
source share
2 answers

, . , .

c3p0 ( , DBC Tomcat, ). c3p0 /WEB-INF/lib :

ComboPooledDataSource dataSource = new ComboPooledDataSource(); 
dataSource.setDriverClass("org.postgresql.Driver"); 
dataSource.setJdbcUrl("jdbc:postgresql://localhost/testdb");
dataSource.setUser("dbuser");
dataSource.setPassword("dbpassword"); 
// ...

Connection connection = null;
// ...
try {
    connection = dataSource.getConnection();
    // ...
} finally {
    // ...
    if (connection != null) try { connection.close(); } catch (SQLException logOrIgnore) {} // Always close resources in finally!
}
+5

Tomcat, JDBC- jar $CATALINA_HOME/lib ( ), Common class loader DBCP , ClassNotFoundException. Tomcat:

      Bootstrap
          |
       System
          |
       Common
       /     \
  Webapp1   Webapp2 ... 

WEB-INF/lib Common class ( ).

$CATALINA_HOME/lib, Tomcat. ( WEB-INF/lib). BalusC , C3P0.

+3

Source: https://habr.com/ru/post/1746372/


All Articles