title: How to use DB2 JDBC driver with Hibernate
body: <p>I keep getting</p>
  
  <blockquote>
    <p>java.lang.ClassNotFoundException: Could not load requested class : com.ibm.db2.jcc.DB2Driver</p>
  </blockquote>
  
  <p>when trying to connect to a DB2 database using Hibernate. The driver jar is referenced as an external library:</p>
  
  <p><a href="https://i.stack.imgur.com/2URmx.png" rel="nofollow noreferrer">Image of Eclipse's "Referenced Library" folder</a></p>
  
  <p>It also shows up in the classpath:</p>
  
  <pre><code>classpathentry kind="lib" path="C:/Program Files (x86)/IBM/SQLLIB/java/db2jcc.jar"/&gt;
  </code></pre>
  
  <p>I can also access the class by importing it in the source code. My <code>persistence.xml</code> looks as follows:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
  &lt;persistence xmlns="http://java.sun.com/xml/ns/persistence"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"
     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="name" transaction-type="RESOURCE_LOCAL"&gt;
        &lt;description&gt;Persistence Unit&lt;/description&gt;
        &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
  
        &lt;class&gt;MyClass&lt;/class&gt;
  
        &lt;properties&gt;
           &lt;property name="javax.persistence.jdbc.driver" value="com.ibm.db2.jcc.DB2Driver" /&gt;
           &lt;property name="javax.persistence.jdbc.url" value="jdbc:db2://url" /&gt;         
           &lt;property name="javax.persistence.jdbc.user" value="user" /&gt;
           &lt;property name="javax.persistence.jdbc.password" value="password" /&gt;
           &lt;property name="hibernate.dialect" value="org.hibernate.dialect.DB2Dialect" /&gt;
  
           &lt;property name="hibernate.hbm2ddl.auto" value="create" /&gt;
           &lt;property name="hibernate.show_sql" value="false" /&gt;
           &lt;property name="hibernate.format_sql" value="true" /&gt;         
        &lt;/properties&gt;
     &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>My suspicion why this does not work is that the class is contained in an external library and not as a maven dependency, because when I replace the DB2 driver by <code>net.ucanaccess.jdbc.UcanaccessDriver</code> (which is contained in a Maven package), the class will be found just fine.</p>
  
  <p>Any idea what I am doing wrong here?</p>