title: java.sql.SQLException: No suitable driver, when accessing the DB
body: <p>I have created a basic Spring 3.1 - Hibernate 4 - Mysql 5.5 web app running on Tomcat 7.
  I'm pooling connections via spring + C3PO.</p>
  
  <p>UPDATE: I'm posting my code as well.</p>
  
  <p>My Spring application context:</p>
  
  <pre><code>&lt;!-- Context --&gt;
  &lt;context:component-scan base-package="com.yl.tomcat" /&gt;
  
  &lt;!-- AOP --&gt;
  &lt;aop:aspectj-autoproxy /&gt;
  
  &lt;!-- Properties --&gt;
  &lt;bean id="applicationProperties"
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
      &lt;property name="location" value="classpath:applicationProperties.properties" /&gt;
  &lt;/bean&gt;
  
  &lt;!-- Data source --&gt;
  &lt;!-- Have spring manage connection management along with connection pooling --&gt;
  &lt;bean id="dataSourceGlobal" class="com.mchange.v2.c3p0.ComboPooledDataSource"
      destroy-method="close"&gt;
      &lt;property name="driverClass" value="${driverClass}" /&gt;
      &lt;property name="jdbcUrl" value="${jdbcUrl" /&gt;
      &lt;property name="user" value="${user}" /&gt;
      &lt;property name="password" value="${password}" /&gt;
  
      &lt;!-- C3P0 Connection pool properties --&gt;
      &lt;property name="minPoolSize" value="${c3p0.min_pool_size}" /&gt;
      &lt;property name="maxPoolSize" value="${c3p0.max_pool_size}" /&gt;
      &lt;property name="unreturnedConnectionTimeout" value="${c3p0.timeout}" /&gt;
      &lt;property name="idleConnectionTestPeriod" value="${c3p0.idle_test_period}"/&gt;
      &lt;property name="maxStatements" value="${c3p0.max_statements}"/&gt;
      &lt;property name="automaticTestTable" value="${c3p0.automatic_test_table}"/&gt;
  &lt;/bean&gt;
  
  &lt;!-- JPA --&gt;
  &lt;!-- Creates a EntityManagerFactory for use with the Hibernate JPA provider --&gt;
  &lt;bean id="entityManagerFactory"
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
      &lt;property name="persistenceUnitName" value="myPU" /&gt;
      &lt;property name="dataSource" ref="dataSourceGlobal" /&gt;
  &lt;/bean&gt;
  
  &lt;!-- In order to enable EntityManager injection --&gt;
  &lt;bean id="persistenceAnnotation"
      class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"&gt;
      &lt;property name="persistenceUnits"&gt;
          &lt;map&gt;
              &lt;entry key="myPU" value="persistence/myPU" /&gt;
          &lt;/map&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;!-- Transactions --&gt;
  &lt;tx:annotation-driven /&gt;
  
  &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
      &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
      &lt;property name="dataSource" ref="dataSourceGlobal" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>As you can see I used a C3PO data source for the pooling, managed by spring container.</p>
  
  <p>My properties file (referred from spring container):</p>
  
  <pre><code>driverClass=com.mysql.jdbc.Driver
  jdbcUrl=jdbc:mysql://localhost:3306/yl
  user=root
  password=pass
  
  c3p0.min_pool_size=5
  c3p0.max_pool_size=20
  c3p0.timeout=5000
  c3p0.idle_test_period=100
  c3p0.max_statements=50
  c3p0.automatic_test_table=test_table
  </code></pre>
  
  <p>Here are my POM dependencies:</p>
  
  <pre><code>    &lt;properties&gt;
      &lt;java-version&gt;1.6&lt;/java-version&gt;
      &lt;org.springframework-version&gt;3.1.0.RELEASE&lt;/org.springframework-version&gt;
      &lt;hibernate.version&gt;4.1.4.Final&lt;/hibernate.version&gt;
      &lt;org.aspectj-version&gt;1.6.9&lt;/org.aspectj-version&gt;
      &lt;org.slf4j-version&gt;1.5.10&lt;/org.slf4j-version&gt;
  &lt;/properties&gt;
  &lt;dependencies&gt;
      &lt;!-- Spring --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
          &lt;version&gt;${org.springframework-version}&lt;/version&gt;
          &lt;exclusions&gt;
              &lt;!-- Exclude Commons Logging in favor of SLF4j --&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;commons-logging&lt;/groupId&gt;
                  &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
              &lt;/exclusion&gt;
          &lt;/exclusions&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
          &lt;version&gt;${org.springframework-version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-beans&lt;/artifactId&gt;
          &lt;version&gt;${org.springframework-version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
          &lt;version&gt;${org.springframework-version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!--Transaction Management Abstraction (depends on spring-core, spring-beans, 
          spring-aop, spring-context) Define this if you use Spring Transactions or 
          DAO Exception Hierarchy(org.springframework.transaction.*/org.springframework.dao.*) --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-tx&lt;/artifactId&gt;
          &lt;version&gt;${org.springframework-version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!--JDBC Data Access Library (depends on spring-core, spring-beans, spring-context, 
          spring-tx) Define this if you use Spring's JdbcTemplate API (org.springframework.jdbc.*) --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-jdbc&lt;/artifactId&gt;
          &lt;version&gt;${org.springframework-version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!--Object-to-Relation-Mapping (ORM) integration with Hibernate, JPA, and 
          iBatis.(depends on spring-core, spring-beans, spring-context, spring-tx) 
          Define this if you need ORM (org.springframework.orm.*) --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
          &lt;version&gt;${org.springframework-version}&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- DB Connection --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;c3p0&lt;/groupId&gt;
          &lt;artifactId&gt;c3p0&lt;/artifactId&gt;
          &lt;version&gt;0.9.1.2&lt;/version&gt;
          &lt;type&gt;jar&lt;/type&gt;
          &lt;scope&gt;compile&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;!-- MySQL database driver --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;mysql&lt;/groupId&gt;
          &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
          &lt;version&gt;5.1.20&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Hibernate --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;
          &lt;version&gt;4.3.0.Final&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
          &lt;version&gt;${hibernate.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.validation&lt;/groupId&gt;
          &lt;artifactId&gt;validation-api&lt;/artifactId&gt;
          &lt;version&gt;1.0.0.GA&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;!-- AspectJ --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
          &lt;artifactId&gt;aspectjrt&lt;/artifactId&gt;
          &lt;version&gt;${org.aspectj-version}&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Logging --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
          &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
          &lt;version&gt;${org.slf4j-version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
          &lt;artifactId&gt;jcl-over-slf4j&lt;/artifactId&gt;
          &lt;version&gt;${org.slf4j-version}&lt;/version&gt;
          &lt;scope&gt;runtime&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
          &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
          &lt;version&gt;${org.slf4j-version}&lt;/version&gt;
          &lt;scope&gt;runtime&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;log4j&lt;/groupId&gt;
          &lt;artifactId&gt;log4j&lt;/artifactId&gt;
          &lt;version&gt;1.2.15&lt;/version&gt;
          &lt;exclusions&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;javax.mail&lt;/groupId&gt;
                  &lt;artifactId&gt;mail&lt;/artifactId&gt;
              &lt;/exclusion&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;javax.jms&lt;/groupId&gt;
                  &lt;artifactId&gt;jms&lt;/artifactId&gt;
              &lt;/exclusion&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;com.sun.jdmk&lt;/groupId&gt;
                  &lt;artifactId&gt;jmxtools&lt;/artifactId&gt;
              &lt;/exclusion&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;com.sun.jmx&lt;/groupId&gt;
                  &lt;artifactId&gt;jmxri&lt;/artifactId&gt;
              &lt;/exclusion&gt;
          &lt;/exclusions&gt;
          &lt;scope&gt;runtime&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;!-- @Inject --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.inject&lt;/groupId&gt;
          &lt;artifactId&gt;javax.inject&lt;/artifactId&gt;
          &lt;version&gt;1&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Misc --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;commons-lang&lt;/groupId&gt;
          &lt;artifactId&gt;commons-lang&lt;/artifactId&gt;
          &lt;version&gt;2.6&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Servlet --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
          &lt;artifactId&gt;servlet-api&lt;/artifactId&gt;
          &lt;version&gt;2.5&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet.jsp&lt;/groupId&gt;
          &lt;artifactId&gt;jsp-api&lt;/artifactId&gt;
          &lt;version&gt;2.1&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
          &lt;artifactId&gt;jstl&lt;/artifactId&gt;
          &lt;version&gt;1.2&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Test --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;junit&lt;/groupId&gt;
          &lt;artifactId&gt;junit&lt;/artifactId&gt;
          &lt;version&gt;4.9&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p>My web.xml is a standard Spring MVC web.xml with the addition of my persistence unit definition:</p>
  
  <pre><code>&lt;persistence-unit-ref&gt;
      &lt;persistence-unit-ref-name&gt;persistence/myPU&lt;/persistence-unit-ref-name&gt;
      &lt;persistence-unit-name&gt;myPU&lt;/persistence-unit-name&gt;
  &lt;/persistence-unit-ref&gt;
  </code></pre>
  
  <p>My DAO is injected with the Entity-manager:</p>
  
  <pre><code>@PersistenceContext
  protected EntityManager entityManager;
  </code></pre>
  
  <p>And last, here is my persistence.xml which is located under my META-INF folder:</p>
  
  <pre><code>&lt;persistence-unit name="myPU" transaction-type="RESOURCE_LOCAL"&gt;
      &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
      &lt;properties&gt;
          &lt;property name="hibernate.transaction.flush_before_completion"
              value="true" /&gt;
          &lt;property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect" /&gt;
          &lt;property name="hibernate.show_sql" value="true" /&gt;
      &lt;/properties&gt;
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p>When trying to access to DB I'm getting java.sql.SQLException: No suitable driver:</p>
  
  <blockquote>
    <p>java.sql.SQLException: No suitable driver
        java.sql.DriverManager.getDriver(DriverManager.java:289)
        com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:223)
        com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:119)
        com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:143)
        com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:132)
        com.mchange.v2.c3p0.impl.C3P0PooledConnectionPoolManager.initializeAutomaticTestTable(C3P0PooledConnectionPoolManager.java:772)
        com.mchange.v2.c3p0.impl.C3P0PooledConnectionPoolManager.createPooledConnectionPool(C3P0PooledConnectionPoolManager.java:696)
        com.mchange.v2.c3p0.impl.C3P0PooledConnectionPoolManager.getPool(C3P0PooledConnectionPoolManager.java:257)
        com.mchange.v2.c3p0.impl.C3P0PooledConnectionPoolManager.getPool(C3P0PooledConnectionPoolManager.java:271)
        com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
        org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:70)
        org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:281)
        org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:297)
        org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:169)
        org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.extractPhysicalConnection(ConnectionProxyHandler.java:82)
        org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.continueInvocation(ConnectionProxyHandler.java:138)
        org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
        $Proxy45.prepareStatement(Unknown Source)
        org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:147)
        org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:166)
        org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:145)
        org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1711)
        org.hibernate.loader.Loader.doQuery(Loader.java:828)
        org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289)
        org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
        org.hibernate.loader.Loader.loadEntity(Loader.java:2033)
        org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:82)
        org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:72)
        org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3719)
        org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:449)
        org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:418)
        org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:204)
        org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:251)
        org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:148)
        org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1079)
        org.hibernate.internal.SessionImpl.access$2200(SessionImpl.java:172)
        org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2425)
        org.hibernate.internal.SessionImpl.get(SessionImpl.java:975)
        org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:807)
        org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:781)
        sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        java.lang.reflect.Method.invoke(Method.java:601)
        org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:365)
        $Proxy44.find(Unknown Source)
        sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        java.lang.reflect.Method.invoke(Method.java:601)
        org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
        $Proxy21.find(Unknown Source)
        com.yl.tomcat.dal.impl.BasicJpaDao.read(BasicJpaDao.java:48)
        com.yl.tomcat.app.bl.UserService.updateUserName(UserService.java:17)
        com.yl.tomcat.web.HomeController.String(HomeController.java:53)
        sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        java.lang.reflect.Method.invoke(Method.java:601)
        org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)
        org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
        org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
        org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
        org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
        org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
        org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)
        org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)
        org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
        org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:722)</p>
  </blockquote>
  
  <p>In similar threads (<a href="https://stackoverflow.com/questions/5556664/how-to-fix-no-suitable-driver-found-for-jdbcmysql-localhost-dbname-error-w">this</a> and <a href="https://stackoverflow.com/questions/11106279/java-sql-sqlexception-no-suitable-driver-when-starting-tomcat-server">this</a>) the solution is provided by putting the mysql driver jar in the server lib folder. ($CATALINA_HOME/lib).
  Currently I have the jar only in my application classpath and I'm wondering if the above solution is the only one available (I don't like it, it couples my application to my tomcat server, which is not optimal in my opinion)?</p>
  
  <p>Anyways - even when I copied the mysql jar to tomcat's lib library it didn't change anything :(
  Did I miss something along the way?</p>
  
  <p>Any help is highly appreciated,
  Yogi</p>