title: Java: No suitable driver found for jdbc:h2
body: <p>I'm having an issue with some of my code, I've searched and tried everything I know of, without any luck.</p>
  
  <hr>
  
  <p><strong>Scenario:</strong></p>
  
  <ul>
  <li>Application checks if JDBC driver exists, in this case, the H2 driver (org.h2.Driver).</li>
  <li><p>If it doesn't exist, the application downloads the JDBC driver and adds it to a ClassLoader like so: (<strong>note</strong>: storageDataManager is a class of mine I use for SQL methods)</p>
  
  <pre><code>   File h2Driver = new File(directory.toString() + File.separator + "lib" + File.separator + "h2.jar");
     if (h2Driver.exists()) {
         URL[] url = new URL[0];
         try {
             url = new URL[]{h2Driver.toURI().toURL()};
             storageDataManager.setClassLoader(new URLClassLoader(url));
         } catch (MalformedURLException ignore) {}
      }
  </code></pre></li>
  </ul>
  
  <hr>
  
  <p>When the storageDataManager runs the first query, it tries to connect with the specified driver, and if it does have a ClassLoader, it uses ClassLoader instead:</p>
  
  <pre><code>if (getClassLoader() != null) {
      getLogging().debug("Loading custom class loader for H2 driver: " + getClassLoader().toString());
      Driver driver = (Driver) Class.forName("org.h2.Driver", true, getClassLoader()).newInstance();
      getLogging().debug("Loaded H2 driver: " + driver.toString() + " - " + driver.getMinorVersion() + " - " + driver.getMajorVersion());
      DriverManager.registerDriver(driver);
  } else {
      getLogging().debug("Loading H2 driver.");
      Class.forName("org.h2.Driver");
  }
  outputDrivers();
  this.con = DriverManager.getConnection(this.url, this.username, this.password);
  break;
  </code></pre>
  
  <p>When I run the application I get this error: </p>
  
  <p>"*No suitable driver found for jdbc:h2:plugins\Odin\data\OdinStorage;AUTO_RECONNECT=TRUE*"</p>
  
  <p>Here's the full log:</p>
  
  <pre><code>[Debug] Loading custom class loader for H2 driver: java.net.URLClassLoader@3bf3d5f4
  [Debug] Loaded H2 driver: org.h2.Driver@67257ce8 - 3 - 1
  [Debug] Checking DriverManager drivers.
  [Debug] Found driver #1: sun.jdbc.odbc.JdbcOdbcDriver
  [Debug] Found driver #2: com.mysql.jdbc.Driver
  [Debug] Found 2 drivers in DriverManager.
  --------------------------- STACKTRACE ERROR ---------------------------
  Class name: java.sql.DriverManager
  Error message: No suitable driver found for jdbc:h2:plugins\Odin\data\OdinStorage;AUTO_RECONNECT=TRUE
  Error cause: null
  File name: null
  Function name: getConnection
  Error line: -1
  --------------------------- STACKTRACE START ---------------------------
  java.sql.DriverManager.getConnection(Unknown Source)
  java.sql.DriverManager.getConnection(Unknown Source)
  com.craftfire.commons.managers.DataManager.connect(DataManager.java:756)
  com.craftfire.commons.managers.DataManager.executeQuery(DataManager.java:526)
  com.craftfire.odin.managers.StorageManager.checkInventoryDatabase(StorageManager.java:65)
  com.craftfire.odin.managers.StorageManager.checkDatabases(StorageManager.java:56)
  com.craftfire.odin.managers.StorageManager.&lt;init&gt;(StorageManager.java:34)
  com.craftfire.odin.managers.OdinManager.loadDatabases(OdinManager.java:206)
  com.craftfire.odin.managers.OdinManager.init(OdinManager.java:75)
  com.craftfire.odin.layer.bukkit.Odin.onEnable(Odin.java:63)
  org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
  org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:374)
  org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:381)
  org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:266)
  org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:248)
  org.bukkit.craftbukkit.CraftServer.&lt;init&gt;(CraftServer.java:200)
  net.minecraft.server.ServerConfigurationManagerAbstract.&lt;init&gt;(ServerConfigurationManagerAbstract.java:50)
  net.minecraft.server.ServerConfigurationManager.&lt;init&gt;(SourceFile:11)
  net.minecraft.server.DedicatedServer.init(DedicatedServer.java:105)
  net.minecraft.server.MinecraftServer.run(MinecraftServer.java:377)
  net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
  ---------------------------- STACKTRACE END ----------------------------
  </code></pre>
  
  <p>My question is then, why doesn't the driver show up in the DriverManager.getDrivers()?</p>
  
  <p><strong>Note:</strong> I do not wish to add the library to the CLASSPATH, which is why I need to find a solution to the issue I described above.</p>
  
  <p>And how can I solve this issue? I simply need to load the H2 JDB driver from a jar.</p>
  
  <p>I have also tried this:</p>
  
  <ul>
  <li>Not use DriverManager.registerDriver(Driver), but use Class.forName("org.h2.Driver", true, getClassLoader()) instead, I've also tried with .newInstance(), neither has worked.</li>
  </ul>
  
  <p>Could anyone provide me with a solution to this?</p>
  
  <p>Thanks!</p>