title: ClassNotFound exception for h2 database class.forname("org.h2.Driver")
body: <p>I'm having trouble getting the Class.forname(&quot;org.h2.Driver&quot;); to not throw an exception. I added the h2*.jar to the build file, and I even got a main file to access the database (the cold will be under the problem code. I'm trying to use dbValues in a Vaadin application and it's just not taking. I can't seem to import any package org.h2.samples; or org.h2.*;</p>
  <p>A note: dbValues is run through a Vaadin project. I don't know if this helps, but it's the only significant difference I can think of between it (doesn't work) and dbTest (does work).</p>
  <pre><code>package com.example.assignment3;
  
  import java.sql.*;
  import java.util.ArrayList;
  
  public class dbValues {
  
      ArrayList&lt;business&gt; a = new ArrayList&lt;business&gt;();
  
      public dbValues(){
          
          business b = new business();
          ArrayList&lt;business&gt; a = new ArrayList&lt;business&gt;();
          
          try {
              Class.forName(&quot;org.h2.Driver&quot;);
          } catch (ClassNotFoundException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
          try {
              
              Connection conn = DriverManager.getConnection(&quot;jdbc:h2:~/test&quot;,&quot;Lucas&quot;,&quot;&quot;);
              Statement stmt = conn.createStatement();
              ResultSet rs = stmt.executeQuery(&quot;SELECT * FROM COMPANIES&quot;);
              while(rs.next()){
                  b.setID(rs.getInt(&quot;ID&quot;));
                  b.setName(rs.getString(&quot;NAME&quot;));
                  b.setSector(rs.getString(&quot;SECTOR&quot;));
                  b.setAddress(rs.getString(&quot;ADDRESS&quot;));
                  b.setProvince(rs.getString(&quot;PROVINCE&quot;));
                  a.add(b);
              }
          } catch (SQLException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
          
      }
      
      public ArrayList&lt;business&gt; returnBusinesses(){
          return a;
      }
  }
  </code></pre>
  <p>Here's the code that seems to work. These two are in the same directory, so that's not the issue.</p>
  <pre><code>import java.sql.*;
  import java.util.ArrayList;
  
  import com.example.assignment3.business;
  public class dbtest {
  public static void main(String[] a)
  throws Exception {
  
      /**
       * Create variables to iterate through when adding to database.
       */
      String dbname = &quot;COMPANIES&quot;;
      int id = 0;
      String name = &quot;&quot;;
      String sector = &quot;&quot;;
      String address = &quot;&quot;;
      String province = &quot;&quot;;
      String query = &quot;&quot;;
      
      Class.forName(&quot;org.h2.Driver&quot;);
      Connection conn = DriverManager.getConnection(&quot;jdbc:h2:~/test&quot;,&quot;Lucas&quot;,&quot;&quot;);
      
      /**
       * Create the business objects.
       */
      business boeing = new business(900162738, &quot;Boeing Canada&quot;, &quot;Aerospace&quot;, &quot;123 Planes St.&quot;, &quot;BC&quot;);
      business odysseyMoon = new business(900687789, &quot;Odyssey Moon&quot;, &quot;Aerospace&quot;, &quot;687 The Moon&quot;, &quot;NS&quot;);
      business vantage = new business(900278382, &quot;Vantage Airport Group&quot;, &quot;Aerospace&quot;, &quot;77 Smith St.&quot;, &quot;NB&quot;);
      business canadaBank = new business(900789213, &quot;Bank of Canada&quot;, &quot;Financial Services&quot;, &quot;2325 Canada blvd.&quot;, &quot;ON&quot;);
      business montrealBank = new business(900890876, &quot;Bank of Montreal&quot;, &quot;Financial Services&quot;, &quot;2132 Bonjour Rd.&quot;, &quot;QC&quot;);
      business rbc = new business(900564738, &quot;Royal Bank of Canada&quot;, &quot;Financial Services&quot;, &quot;132 Clifton St.&quot;, &quot;NB&quot;);
      business ubisoft = new business(900547967, &quot;Ubisoft Halifax&quot;, &quot;Interactive Media&quot;, &quot;2000 Barrington St.&quot;, &quot;NS&quot;);
      business scotiaBank = new business(900345273, &quot;Scotia Bank&quot;, &quot;Financial Services&quot;, &quot;Yahmon Rd.&quot;, &quot;NS&quot;);
      business propaganda = new business(900101928, &quot;Propaganda Games&quot;, &quot;Interactive Media&quot;, &quot;25 Queen St.&quot;, &quot;NT&quot;);
      business ea = new business(900162739, &quot;EA Montreal&quot;, &quot;Interactive Media&quot;, &quot;54 Gagnon St.&quot;, &quot;QC&quot;);
      
      /**
       * Create the arraylist that will be iterated through when adding
       * to the database and then add them to that list.
       */
      ArrayList&lt;business&gt; businesses = new ArrayList&lt;business&gt;();
      businesses.add(boeing);
      businesses.add(odysseyMoon);
      businesses.add(vantage);
      businesses.add(canadaBank);
      businesses.add(montrealBank);
      businesses.add(rbc);
      businesses.add(ubisoft);
      businesses.add(scotiaBank);
      businesses.add(propaganda);
      businesses.add(ea);
      
      /**
       * Perform the statement that populates the database.
       */
      try {
          Statement stmt = conn.createStatement();
          for(int i = 0; i &lt; businesses.size(); i++){
              id = businesses.get(i).getID();
              name = businesses.get(i).getName();
              sector = businesses.get(i).getSector();
              address = businesses.get(i).getAddress();
              province = businesses.get(i).getProvince();
              query = &quot;INSERT INTO &quot; + dbname + &quot; VALUES(&quot;+ id +&quot;, '&quot;+ name +&quot;', '&quot;+ sector +&quot;', '&quot;+ address +&quot;', '&quot;+ province +&quot;');&quot;;
              System.out.println(query);
              stmt.execute(query);
          }
          //stmt.execute(&quot;DELETE FROM COMPANIES;&quot;);
  
      } catch (SQLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  }
  }
  </code></pre>
  <p>So any ideas on the issues? I've got about 24 hours to get this to work.</p>
  <p><a href="https://i.stack.imgur.com/yDfMR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yDfMR.png" alt="Shows the paths on the side" /></a></p>