Announcement Announcement Module
Collapse
No announcement yet.
Could not load driverClass com.mysql.jdbc.Driver Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Could not load driverClass com.mysql.jdbc.Driver

    I have encountered the problem as the title specified, and could not get it solved.

    here is the stack trace

    Code:
    WARNING: Could not load driverClass com.mysql.jdbc.Driver          
    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver          
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
    	at java.lang.Class.forName0(Native Method)
    	at java.lang.Class.forName(Class.java:169)
    	at com.mchange.v2.c3p0.DriverManagerDataSource.ensureDriverLoaded(DriverManagerDataSource.java:100)
    	at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:132)
    	at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
    	at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
    	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
    	at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
    	at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
    	at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
    	at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
    Context configure:

    Code:
    <!--   WORKS
    	<bean id="dataSource"
    		class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    		<property name="driverClassName" value="${jdbc.driverClassName}" />
    		<property name="url" value="${jdbc.url}" />
    		<property name="username" value="${jdbc.username}" />
    		<property name="password" value="${jdbc.password}" />
    	</bean>
    	-->
            <!-- DOESN'T WORK -->
    	<bean id="dataSource"
    		class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    		<property name="driverClass" value="${jdbc.driverClassName}" />
    		<property name="jdbcUrl" value="${jdbc.url}" />
    		<property name="user" value="${jdbc.username}" />
    		<property name="password" value="${jdbc.password}" />
    		<property name="maxStatements" value="${jdbc.maxStatements}" />
            <property name="maxIdleTime" value="${jdbc.maxIdleTime}" />
            <property name="minPoolSize" value="${jdbc.minPoolSize}" />
            <property name="maxPoolSize" value="${jdbc.maxPoolSize}" />
            <property name="initialPoolSize" value="${jdbc.initialPoolSize}" />
            <property name="acquireIncrement" value="${jdbc.acquireIncrement}" />
            <property name="numHelperThreads" value="${jdbc.numHelperThreads}" />
            <property name="idleConnectionTestPeriod" value="${jdbc.idleConnectionTestPeriod}" />
            <property name="acquireRetryAttempts" value="${jdbc.acquireRetryAttempts}" />
    	</bean>
    	
    	<!-- DOESN'T WORK
    	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    		<property name="driverClassName" value="${jdbc.driverClassName}" />
    		<property name="url" value="${jdbc.url}" />
    		<property name="username" value="${jdbc.username}" />
    		<property name="password" value="${jdbc.password}" />
    	</bean>
    	-->
    Neither c3p0 nor dbcp works, but spring DriverManagerDataSource works.

    Same for both mysql driver and MS-sql driver. Dependencies have been correctly loaded. Tried to put the driver jar to both tomcat/lib and WEB-INF/lib but doesn't work. The tomcat server (7.0) been added to the STS servers.

    STS 2.9.1.RELEASE - maven webapp

    Any one has any clue about this? Thanks in advance

  • #2
    Hey!

    Did you check whether the driver JAR file is deployed correctly to the Tomcat app? Please attach a sample project at reproduces the problem, so that we can find the cause.

    Thanks,
    Martin

    Comment


    • #3
      Thanks Martin for you quick response, I finally solved this problem by using plain strings directly rather than parameters from a property file. But I am still wondering to know why.

      ==== Here is more details ====

      ----- A working copy of context config -----

      Code:
      <bean id="BPEcm-DataSource"
      		class="com.mchange.v2.c3p0.ComboPooledDataSource"
      		lazy-init="true" destroy-method="close">
      		<property name="driverClass" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
      		<property name="jdbcUrl" value="jdbc:sqlserver://x.x.x.x:1433;databaseName=aaa" />
      		<property name="user" value="aaa" />
      		<property name="password" value="aaa />
      		<property name="maxStatements" value="0" />
              <property name="maxIdleTime" value="1800" />
              <property name="minPoolSize" value="3" />
              <property name="maxPoolSize" value="20" />
              <property name="initialPoolSize" value="5" />
              <property name="acquireIncrement" value="5" />
              <property name="numHelperThreads" value="6" />
              <property name="idleConnectionTestPeriod" value="3600" />
              <property name="acquireRetryAttempts" value="5" />
      	</bean>
      ---- Not working if from property file ----

      Code:
      <bean id="BPEcm-DataSource"
      		class="com.mchange.v2.c3p0.ComboPooledDataSource"
      		lazy-init="true" destroy-method="close">
      		<property name="driverClass" value="${jdbc.driverClassName}" />
      		<property name="jdbcUrl" value="${jdbc.url}" />
      		<property name="user" value="${jdbc.username}" />
      		<property name="password" value="${jdbc.password}" />
      		<property name="maxStatements" value="${jdbc.maxStatements}" />
              <property name="maxIdleTime" value="${jdbc.maxIdleTime}" />
              <property name="minPoolSize" value="${jdbc.minPoolSize}" />
              <property name="maxPoolSize" value="${jdbc.maxPoolSize}" />
              <property name="initialPoolSize" value="${jdbc.initialPoolSize}" />
              <property name="acquireIncrement" value="${jdbc.acquireIncrement}" />
              <property name="numHelperThreads" value="${jdbc.numHelperThreads}" />
              <property name="idleConnectionTestPeriod" value="${jdbc.idleConnectionTestPeriod}" />
              <property name="acquireRetryAttempts" value="${jdbc.acquireRetryAttempts}" />
      	</bean>
      here is the property file

      Code:
      jdbc.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver                     
      jdbc.url=jdbc:sqlserver://x.x.x.x:1433;databaseName=aaa
      jdbc.username=aaa
      jdbc.password=aaa
      ========== End of example ====================

      Again, with the property file org.springframework.jdbc.datasource.DriverManagerD ataSource works but not c3p0 and DBCP.

      Thanks in advance.

      Comment


      • #4
        Where is the properties file located? How does you PPC setup look like? Does the behavior change if you use SpEL instead of the PPC? E.g.

        Code:
        <util:properties id="props" location="classpath:foo.properties" />
        
        <bean …>
          <property name="key" value="#{props['jdbc.username']}" />
        </bean>

        Comment

        Working...
        X