4

I am trying to use the Squirrel SQL client to connect to a H2 server instance.

The problem I am facing is that when I hit the "connect" button of the server I want to connect to, then I am getting a:

ClassNotFoundException: org.h2.Driver

I thought it was because h2.jar was not in the classpath. Then I edited squirrel-sql.bar to try two things.

The first thing I tried is to add the JAR into the PATH like this:

SET PATH=%PATH%;C:\Program Files\squirrel-sql-3.5.3\plugins\h2.jar

Then I restarted Squirrel. Same error.

Then I tried adding:

set TMP_CP=%TMP_CP%;"C:\Program Files\squirrel-sql-3.5.3\plugins\h2.jar"

Then I restarted Squirrel. Same error.

When I look at the console, I can see that h2.jar is in the PATH and/or the SQUIRREL_CP but the same error occurs all the time.

I am wondering if I am not forgetting something bout how to install/configure SQuirrel and/or H2?

Neoasimov
  • 1,111
  • 2
  • 10
  • 17

3 Answers3

4

Rather than modifying the batch files every time you use a different driver just modify the drivers classpath through the GUI.

Double click on the appropriate driver in the Drivers tab then click on the "Extra Class Path" tab and add the driver jar.

You can find more information under "How to connect to a Database" in the SQuirreL section in the Help file. Press F1 in SQuirreL to see the Help file. You can see a screenshot at http://www.squirrelsql.org/screenshots/driver.html

Colin Bell
  • 361
  • 2
  • 4
  • Nice answer, this solved my problem: "Extra Class Path". And more: The jar-file-path to fill here might be to the just-downloaded-jar, but instead, I recommend to refer to otthe instance of the same file, which you probably have via Maven, in your /.m2/ dir. (It works for me) ..the bonus is, that you have just one version of the library, and all your apps-project uses the same version of the squirrel. – Franta Jun 29 '17 at 08:11
  • So when you set up the H2 Driver, till the time red driver icon gets green, when you restart the Squirrel. Then, set up yet your Alias: The connection string. Note, that whatever checkbox you set (i.e. auto logon), cannot be changed then, sadly. (you will have to set up the Alias again, with your desired difference.) – Franta Jun 29 '17 at 08:14
  • about env-vars: With the "Extra Class Path" (in Squirrel internally) used (and Maven), you do not need to set up any new environment-variable within your OS. (to oppose the previous answers here higher) – Franta Jun 29 '17 at 08:16
2

I found the issue to my problem. I was linking to the h2 file in Squirrel SQL. However, I had to link to the h2 file from the H2 application... What I did to solve my issue is to add a line to the addpath.bat file such that the file looks like:

set TMP_CP=%TMP_CP%;%1
set TMP_CP=%TMP_CP%;"C:\Program Files (x86)\H2\bin\h2-1.4.181.jar"

Then I restarted Squirrel SQL and everything was working as expected!

Neoasimov
  • 1,111
  • 2
  • 10
  • 17
1

I'm listing the exact steps I followed to add the driver as even though Colin Bell has already given a good answer, without following the final step 4. I still couldn't get this to work.

  1. Download http://www.h2database.com/automated/h2-latest.jar and save it somewhere, in my case ~/drivers/h2-latest.jar
  2. Edit the existing h2 driver.
  3. On the 'Extra Class Path' tab add the driver
  4. Click 'List Drivers' - org.h2.Driver should appear in the 'Class Name' field (as detailed in the link from Colin's answer: http://www.squirrelsql.org/screenshots/driver.html)

I was missing the final step of clicking 'List Drivers' since it already had org.h2.Driver in the 'Class Name' before I tried to add it. But without this step it was still giving the error: Could not find class org.h2.Driver in neither the Java class path nor the Extra class path of the H2 driver definition: java.lang.ClassNotFoundException: org.h2.Driver

Chris R
  • 2,464
  • 3
  • 25
  • 31