Jdbc Connection Pool with Sql Server 2008 fails

I am trying to turn my jdbc code to use Connection Pool functionality on Tomcat. My system is a jsp/servlet application that connects to an SQL Server 2008. So, lets get to the code…

My Connection class looks like this:

  • How do I change the date format of a DataBinder.Eval in asp.net?
  • Is the order of comparisant important in a join query?
  • SQL query in NodeJS hours are off when formatting date
  • SQL Server: Create new query that matches prices and values from two separate queries
  • Calling stored procedure from another stored procedure SQL Server
  • A better way to achieve INSERT without hitting the database multiple times
  •     import org.apache.tomcat.jdbc.pool.DataSource;
        import org.apache.tomcat.jdbc.pool.PoolProperties;
        //... some more imports
    public class DbPooledConnectionToMSSQL {
        public String dbsource ;
        private Connection dbCon;
        private DataSource datasource = new DataSource();
        private PoolProperties p = new PoolProperties();
        public DbPooledConnectionToMSSQL() {
            dbsource = "jdbc:sqlserver://xxx.xxx.x.x:1433;database=xxx";
            String user = "user";
            String password = "pass";
        public boolean connect() throws ClassNotFoundException, SQLException {
            try {
                if (dbCon == null) {
                    System.err.println("Creating Pooled Connection....");
                    dbCon = datasource.getConnection(); //<-- here is the exception
                    System.err.println("!!! Pooled Connection creation OK");
                } else {
                    System.err.println("!!! Connection EXIST not creation");
            } catch (SQLException e) {
                return false;
            } catch (Exception e) {
                return false;
            return true;
        //more code below

    Now, in my runner class I initialize this class and try to connect to my database, but I get the famous ClassNotFoundException on the command dbCon = datasource.getConnection();

    I am sure that the Connection Driver is in place because it is already used in my regular jdbc code (not the Connection Pooling) and works just fine.

    I also tried to use com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource as driver class but I also get the same exception:

    java.sql.SQLException: com.microsoft.sqlserver.jdbc.SQLServerDriver
        at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:254)
        at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:182)
        at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:702)
        at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:634)
        at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:488)
        at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:144)
        at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:116)
        at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:103)
        at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:127)
        at admin.db.DbPooledConnectionToMSSQL.connect(DbPooledConnectionToMSSQL.java:97)
    Caused by: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:270)
        at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:246)

    What do I do wrong here? Is there another jdbc Driver that could do the job?

    One Solution collect form web for “Jdbc Connection Pool with Sql Server 2008 fails”

    Ok, found the problem and the answer is pretty simple. Looking at the specification for PoolProperties , it says that :

    setDriverClassName(): The fully qualified Java class name of the JDBC driver to be used. The driver has to be accessible from the same classloader as tomcat-jdbc.jar

    So even the driver was accessible by my application, it was not accessible by Tomcat. So putting the driver in $CATALINA_HOME/libs directory and restarting Tomcat solved this issue.

    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.