9

I am using one method which return me a datasource. The method is as below:

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 am calling these method from dao. and with all this I am using ibatis for my OR mapping. When I run my test case by junit test it is giving me a 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
"
Vamsi Emani
  • 10,072
  • 9
  • 44
  • 71
Chitresh
  • 3,022
  • 12
  • 35
  • 40

6 Answers6

10

By downloading and adding HSQLDB jar in class path from here

jmj
  • 237,923
  • 42
  • 401
  • 438
  • i cannot add the jar in my classpath apart from this if you have a other suggestion to resolve this – Chitresh Feb 21 '11 at 12:33
  • why ??, *no other solution exist* – jmj Feb 21 '11 at 12:34
  • @Chitresh: since that's the only correct solution, you're out of luck. – Joachim Sauer Feb 21 '11 at 12:35
  • hi i can't add jar in my classpath, if you have a other suggestion except this plz tell me i had tried adding jar in my tomcat server lib, but it is not getting from there also – Chitresh Feb 21 '11 at 12:35
  • 1
    `i had tried adding jar in my tomcat server lib,` && `hi i can't add jar in my classpath,` will return false. it should work. retry putting the jar in `common\lib` – jmj Feb 21 '11 at 12:38
  • hi i add the jar in my project build path and the previous problem was solved but i got a new exception the exception is: – Chitresh Feb 22 '11 at 04:14
5

The previous answers here were right, and wrong.

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

Wil
  • 349
  • 3
  • 12
5

If you're 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

ekcrisp
  • 1,967
  • 1
  • 18
  • 26
1

If you have already downloaded the HSQLDB jar file and properly installed then I would check the classpath.

Luixv
  • 8,590
  • 21
  • 84
  • 121
  • if have to do without adding it into a classpath then how i can do. i got one solution to add a jar in my tomcat lib, but it is also giving me a same exception. do you have any idea how to reslove this – Chitresh Feb 21 '11 at 12:42
  • Most probably you should add to your build path. I am assuming that you are using Eclipse, then right click into your project, click properties and then add it to your build path. Where did you put your jar file? and how? You can drag and drop the file into a lib directory of your project. – Luixv Feb 21 '11 at 12:49
0

Just use Grab:

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

more info: http://groovy-lang.org/databases.html

Behrouz Seyedi
  • 306
  • 1
  • 18
0

Try following dependency config in your pom.xml

<dependency>
   <groupId>org.hsqldb</groupId>
   <artifactId>hsqldb</artifactId>
   <classifier>jdk8</classifier>
   <version>2.6.1</version>        
</dependency>

For me adding that classifier line solved an issue. Please see below recommendation in hsqldb repo. https://sourceforge.net/p/hsqldb/bugs/1644/

lord5et
  • 422
  • 7
  • 6