Org.hsqldb.jdbcDriver Class NotFoundException when running a junit test for a method

I use one method that returns me a data source. The method is as follows:

public static DataSource getDataSource(){ String url; //url="jdbc:hsqldb:file:"+filePath; url = "jdbc:hsqldb:file:D:/EclipseWorskpace/ew-pg/lmexadapter/hsqldb-example/src/main/webapp/WEB-INF/data/db/hsqldb.jar"; BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setUsername("SA"); basicDataSource.setPassword("password"); basicDataSource.setDriverClassName("org.hsqldb.jdbc.JDBCDriver"); basicDataSource.setUrl(url); System.out.println("$$$$$$$$ URL is : " + url); return basicDataSource; } 

And I call this method from dao. and with all this I use ibatis for my OR mapping. When I run my test case using the junit test, it gives me an exception:

 " org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'org.hsqldb.jdbcDriver' at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1259) at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1192) at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:884) at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:113) at org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy$TransactionAwareInvocationHandler.invoke(TransactionAwareDataSourceProxy.java:213) ... 35 more Caused by: java.lang.ClassNotFoundException: org.hsqldb.jdbcDriver at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:169) at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1253) ... 39 more " 
+8
java hsqldb
source share
5 answers

By loading and adding the HSQLDB jar to the class path from here

+10
source share

The previous answers here were right and wrong.

HSQLDB must be added to the classpath. The problem is that in previous answers, the questioner pointed to old versions of the project that did not have the class they were looking for. The class that was not found is only in the second version of HSQLDB, available at http://sourceforge.net/projects/hsqldb/files/hsqldb/hsqldb_2_3/

+5
source share

If you are using Maven, try adding

 <dependency> <groupId>org.hsqldb</groupId> <artifactId>hsqldb</artifactId> <version>2.4.0</version> <scope>runtime</scope> </dependency> 

to your pom.xml

+2
source share

If you already downloaded the HSQLDB jar file and installed it correctly, I would check the path to it.

+1
source share

Just use Grab:

 @Grab('org.hsqldb:hsqldb:2.3.3') @GrabConfig(systemClassLoader=true) 

additional information: http://groovy-lang.org/databases.html

0
source share

All Articles