how to resolve org.apache.commons.dbcp.SQLNestedException
I am using hsqldb standalone as my database. i have a hsqldb.jar(hsqldb-2.0.0)
which i added on my project build path so my project will find out where is my hsqldb.jar
. i am using spring with these. my spring bean is:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="sqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="dataSource">
<ref local="adapterDataSource" />
</property>
<property name="configLocation"
value="classpath:/com/hsqldb/example/dao/ibatis/SqlMapConfig.xml" />
</bean>
<bean id="adapterDataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="data/db/hsqldb.jar" />
<property name="username" value="SA" />
<property name="password" value="password" />
</bean>
<bean id="testingDao" class="com.hsqldb.example.dao.TestingDao"
init-method="setTestDao" depends-on="moodleAuthenticationDetails">
<property name="sqlMapClient">
<ref local="sqlMapClient" />
</property>
</bean>
<bean id="moodleAuthenticationDetails"
class="com.hsqldb.example.HsqlDBAuthentication"></bean>
</beans>
and i have a method which will return me a data source which is as below :
public static DataSource getDataSource(String filePath){
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("jdbc:mysql://IP/moodle");
basicDataSource.setUrl(url);
System.out.println("$$$$$$$$ URL is : " + url);
return basicDataSource;
}
but while running my test case by junit test it's giving me an exception :
org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class 'org.hsqldb.jdbcDriver' for connect URL 'data/db/hsqldb.jar'
at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1273)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1192)
at org.apache.开发者_如何学Ccommons.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.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:264)
at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1266)
... 39 more
please help to resolve this.
Thank you
The BasicDataSource
url
property in your Spring config should not be the path to your jar. See some examples of working Spring configs here.
(The DataSource
class you've written won't do anything unless you make Spring aware of it. But you don't have to write such a class -- just fix the url
property in your config.)
精彩评论