Could not load driverClass org.hsqldb.jdbcDriver in vert.x-examples/JDBC/simple example

567 views
Skip to first unread message

pahan

unread,
Jun 26, 2016, 1:53:48 AM6/26/16
to vert.x
Hi all,
   I'm Pahan, a student from Sri Lanka. I'm new to vert.x and I'm trying to contribute to vert.x. Therefore as a start, I tried to run the vert.x examples given in github/vertx-examples. When I tried to run JDBC simple example, I get this exception. I already installed HSQL and added HSQL lib to my PATH variable. Am I missing something?   

Could not load driverClass org.hsqldb.jdbcDriver 
java.lang.ClassNotFoundException: org.hsqldb.jdbcDriver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.mchange.v2.c3p0.DriverManagerDataSource.ensureDriverLoaded(DriverManagerDataSource.java:143)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:159)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:161)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:147)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:202)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)

I also would like to hear some beginner tips from anyone to get a good start.

Jez P

unread,
Jun 26, 2016, 6:40:46 AM6/26/16
to vert.x
Putting a lib on the path doesn't automatically put it on the class path. You need to add the HSQL lib to your class path. 

Tim Fox

unread,
Jun 26, 2016, 3:47:35 PM6/26/16
to vert.x
If run it in the IDE with the main method as described in the instructions the right driver will be on the classpath.

Tim Fox

unread,
Jun 26, 2016, 3:49:04 PM6/26/16
to vert.x

pahan

unread,
Jun 27, 2016, 3:25:46 AM6/27/16
to vert.x
Hi,
   I was following the instructions given in the README and I ran the examples from the command line. I added the lib folder to the class path as suggested and I still get the exception. I have MySQL installed and running. Does it interfere in any way with HSQL?

Ricardo Hernandez

unread,
Jun 27, 2016, 5:53:35 AM6/27/16
to vert.x
Hi,

The library needs to be available in Vert.x classpath so it can find it. Apparently the -cp option (which I believe is the method you are using) won't make it available for Vert.x (I found this older answer), in contrary to other approaches of running Vert.x such as Maven, fatjar, Docker, etc.

Make sure your CLASSPATH environment variable is up to date with the location of your driver.

Tim Fox

unread,
Jun 27, 2016, 8:14:10 AM6/27/16
to vert.x
Run it in the IDE, it's simpler :)

Clement Escoffier

unread,
Jun 27, 2016, 12:27:31 PM6/27/16
to ve...@googlegroups.com
Hi,

By default, the JDBC client uses C3PO as connection pool. C3PO requires the JDBC driver to be loaded from the (genuine) classpath classloader. That means the the JDBC driver (HSQL in your case) must be:

* in the vertx/lib directory if your are using the `vertx` command line tools
* in the fat jar if you are using a fat jar
* in the (genuine) classpath if your are using regular `java` command

In the classpath means in the java classpath, not using the vert.x `-cp` parameter, some something like: java -cp hsql.jar:rest of the classpath io.vertx.core.Launcher run your.verticle

This is related to C3PO, other connection pool may accept loading the driver from a different classloader.


Clement

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/63550e8c-d327-4553-a709-a202c7b41043%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

pahan

unread,
Jun 28, 2016, 6:56:08 AM6/28/16
to vert.x
Hi Clement,

Your answer was very useful. I was using vertx command line tools (I should have mentioned this earlier), which needed the HSQL.jar file in the vertx/lib to load the driver. Adding HSQL.jar to vertx/lib solved the problem. Thanks a lot.

Thanks everyone.
Reply all
Reply to author
Forward
0 new messages