java.sql.SQLException: No suitable driver found for jdbc:db2:
- by Celia
Im using hibernate to connect to my DB2 database.
I got java.sql.SQLException: No suitable driver found for jdbc:db2://ldild4268.mycompany.com:55000/myDB.
I have db2jcc.jar, db2jcc_javax.jar, db2jcc_license_cu.jar, db2policy.jar, db2ggjava.jar and db2umplugin.jar added into my Java Build Path.
I am able to connect to my database through SQuirrel.
database.properties:
jdbc.driverClassName=com.ibm.db2.jcc.DB2Driver
jdbc.url=jdbc:db2://ldild4268.mycompany.com:55000/myDB
jdbc.username=uname
jdbc.password=pwd
datasource.xml:
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>/WEB-INF/database.properties</value>
</property>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
hibernate.xml:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.DB2Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>/myModel.hbm.xml</value>
</list>
</property>
</bean>
myModel.hbm.xml:
<hibernate-mapping>
<class name="com.myCompany.model.myModel" table="table1" catalog="">
<composite-id>
<key-property name="key1" column="key1" length="10"/>
<key-property name="key2" column="key2" length="19"/>
</composite-id>
<property name="name" type="string">
<column name="Name" length="50"/>
</property>
</class>
</hibernate-mapping>
myModelDaoImpl:
@Repository("myModelDao")
public class myModelDaoImpl extends PortfolioHibernateDaoSupport implements myModelDao{
private SessionFactory sessionFactory;
public List<Date> getKey1() {
return this.sessionFactory.getCurrentSession()
.createQuery("select pn.key1 from com.myCompany.model.myModel pn")
.list();
}
public String getPs() {
String query = "select pn.name from com.myCompany.model.myModel pn where pn.key1='2011-09-30' and pn.key2=1049764";
List list = getHibernateTemplate().find(query);
}
}
also, the method getKey1 throws nullPointer exception. How can I use createquery instead of hibernateTemplate?
Thanks in advance!