title: Advice needed to understand cause of java.sql.SQLException: No suitable driver found for jdbc:postgresql error
body: <p>I am writing a web application and I am trying to use hibernate to connect to a PostgreSQL 8.4.13 database in my project. I have been unsuccessful so far, I get the following error (java.sql.SQLException: No suitable driver found for jdbc:postgresql://localhost:5432/mcappdb) – the trace is at the bottom. I have been through many forums and not found a solution to my problem:</p>
  
  <p>I have included the following dependencies into my pom.xml and this builds successfully. I am deploying to jboss eap 6 using ‘mvn jboss-as:deploy’.</p>
  
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
          &lt;version&gt;4.2.5.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;4.2.5.Final&lt;/version&gt;
      &lt;/dependency&gt;  
      &lt;dependency&gt;
          &lt;groupId&gt;postgresql&lt;/groupId&gt;
          &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
          &lt;version&gt;8.4-702.jdbc4&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>I have configured the persistence.xml file as follows:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
           http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt;
  
  &lt;persistence-unit name="mcappdb" transaction-type="RESOURCE_LOCAL"&gt;
      &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
  
      &lt;class&gt;uk.co.metasphere.entities.userConfig&lt;/class&gt;
  
      &lt;properties&gt;
          &lt;property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/&gt;
          &lt;property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/mcappdb"/&gt;
          &lt;property name="hibernate.connection.username" value="mcapp"/&gt;
          &lt;property name="hibernate.connection.password" value="mc2000"/&gt;
          &lt;property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/&gt;
      &lt;/properties&gt;
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p></p>
  
  <p>This file is in the src/main/resources/META-INF directory. </p>
  
  <p>The app deploys successfully but raises the error when it tries to connect to the database with hibernate. My code to connect from my app is as follows:</p>
  
  <pre><code>EntityManagerFactory emf = Persistence.createEntityManagerFactory("mcappdb");
  EntityManager em1 = emf.createEntityManager();
  userConfig uscon = em1.find(userConfig.class, 0);
  </code></pre>
  
  <p>The error is raised on the call to em1.find().</p>
  
  <p>I have read through many forum posts. Most indicate the error is either because the driver is not on the classpath or the defined url is wrong. The driver jar file is in /target/MCapp-1.0/WEB-INF/lib/postgresql-8.4-702.jdbc4.jar and is I believe deployed in the same place as all the other dependant jar files (correct?). The url I use works if I connect via a basic JBDC connection (rather than hibernate) so I believe that is also ok.</p>
  
  <p>Another suggestion is that I need to load the driver using the following code:</p>
  
  <pre><code>Class.forName("org.postgresql.Driver");
  </code></pre>
  
  <p>This doesn’t help either.</p>
  
  <p>Since the straight forward JDBC connection works ok it seems that Hibernate is the problem? Can anyone advise me of what the problem might be or how I could investigate it further? Where/how does hibernate look for the database driver? Do I need to deploy it to another directory or make another configuration step so that it can find it?</p>
  
  <p>Any help gratefully received.</p>
  
  <p>Trace of error:</p>
  
  <pre><code>15:12:53,932 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/MCapp-1.0].[Mcapp Application]] (http-/0.0.0.0:8080-1) Servlet.service() for servlet Mcapp Application threw exception: java.sql.SQLException: No suitable driver found for jdbc:postgresql://localhost:5432/mcappdb
  at java.sql.DriverManager.getConnection(DriverManager.java:596) [rt.jar:1.7.0_25]
  at java.sql.DriverManager.getConnection(DriverManager.java:187) [rt.jar:1.7.0_25]
  at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:193) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:278) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:297) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:169) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.extractPhysicalConnection(ConnectionProxyHandler.java:82) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.continueInvocation(ConnectionProxyHandler.java:138) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at com.sun.proxy.$Proxy17.prepareStatement(Unknown Source)
  at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:147) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:166) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:145) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1711) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at org.hibernate.loader.Loader.doQuery(Loader.java:828) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at org.hibernate.loader.Loader.loadEntity(Loader.java:2033) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:82) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:72) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3719) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:449) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:418) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:204) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:251) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:148) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1079) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at org.hibernate.internal.SessionImpl.access$2200(SessionImpl.java:172) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2425) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at org.hibernate.internal.SessionImpl.get(SessionImpl.java:975) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:802) [hibernate-entitymanager-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:776) [hibernate-entitymanager-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
  at uk.co.metasphere.McappUI.init(McappUI.java:210) [classes:]
  at com.vaadin.ui.UI.doInit(UI.java:607) [vaadin-server-7.1.5.jar:7.1.5]
  at com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:223) [vaadin-server-7.1.5.jar:7.1.5]
  at com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:73) [vaadin-server-7.1.5.jar:7.1.5]
  at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:37) [vaadin-server-7.1.5.jar:7.1.5]
  at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1371) [vaadin-server-7.1.5.jar:7.1.5]
  at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:238) [vaadin-server-7.1.5.jar:7.1.5]
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.1.Final-redhat-1.jar:1.0.1.Final-redhat-1]
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.16.Final-redhat-1.jar:]
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.16.Final-redhat-1.jar:]
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.16.Final-redhat-1.jar:]
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.16.Final-redhat-1.jar:]
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:489) [jbossweb-7.0.16.Final-redhat-1.jar:]
  at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]
  at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.16.Final-redhat-1.jar:]
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.16.Final-redhat-1.jar:]
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.16.Final-redhat-1.jar:]
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.16.Final-redhat-1.jar:]
  at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.16.Final-redhat-1.jar:]
  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:679) [jbossweb-7.0.16.Final-redhat-1.jar:]
  at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:931) [jbossweb-7.0.16.Final-redhat-1.jar:]
  at java.lang.Thread.run(Thread.java:724) [rt.jar:1.7.0_25]
  </code></pre>