how to connect hibernate and DB2

1 Answers

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 file and via programmatic configuration (more specifically, see Hibernate Reference Documentation, chapter 1 and 2. Here is an simple example, how to do this:


SessionFactory sf = new Configuration()
.setProperty("hibernate.connection.driver_class", "")
.setProperty("hibernate.connection.url", "jdbc:db2://yourDbServerUrl:port/databaseName")
.setProperty("hibernate.connection.username", "yourUsername")
.setProperty("hibernate.connection.password", "yourPassword")


hibernate.connection.driver_class =
hibernate.connection.url = jdbc:db2://yourDbServerUrl:port/databaseName
hibernate.connection.username = yourUsername
hibernate.connection.password = yourPassword

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

  • what Configuration I have to do in hibernate configuration file?
  • Do I have to set any classpath variable?
  • I know there are two jars for DB2 (db2jcc.jar & db2jcc_license_cu.jar). Is there any other jar I may need?

Thanks in advance.

Hibernate and DB2 data fetching

Problem is with database schema.

i was using


when I use


it works. Because in DB schema was schema1.