I am running an application that used struts and hibernate. I am currently using Derby database. Now i have to shift on DB2 database.
Please tell me
Thanks in advance.
It should work with db2jcc.jar
Add below properties to your hibernate.cfg.xml
<property name="hibernate.dialect">org.hibernate.dialect.DB2Dialect</property>
<property name="hibernate.connection.driver_class">com.ibm.db2.jcc.DB2Driver</property>
<property name="connection.url">jdbc:db2://<host>:<port50000>/<dbname></property>
<property name="connection.username">dbusername</property>
<property name="connection.password">dbpassword</property>
Change last 3 properties according to your configuration
If your DB2 driver supports JDBC approach (and it does), you need to set connection properties. There are three ways of doing so: via xml, via hibernate.properties
file and via programmatic configuration (more specifically, see Hibernate Reference Documentation, chapter 1 and 2. Here is an simple example, how to do this:
Programmatically:
SessionFactory sf = new Configuration()
.setProperty("hibernate.connection.driver_class", "com.ibm.db2.jcc.DB2Driver")
.setProperty("hibernate.connection.url", "jdbc:db2://yourDbServerUrl:port/databaseName")
.setProperty("hibernate.connection.username", "yourUsername")
.setProperty("hibernate.connection.password", "yourPassword")
.buildSessionFactory();
Via hibernate.properties
:
hibernate.connection.driver_class = com.ibm.db2.jcc.DB2Driver
hibernate.connection.url = jdbc:db2://yourDbServerUrl:port/databaseName
hibernate.connection.username = yourUsername
hibernate.connection.password = yourPassword
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With