开发者

org.hsqldb.jdbcDriver ClassNotFoundException while running junit test for a method

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(N开发者_开发技巧ative 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
"


By downloading and adding HSQLDB jar in class path from here


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/


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


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


Just use Grab:

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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜