[ACCEPTED]-how to connect hibernate and DB2-db2
It should work with db2jcc.jar
Add below properties 2 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 1 to your configuration
If your DB2 driver supports JDBC approach 6 (and it does), you need to set connection 5 properties. There are three ways of doing 4 so: via xml, via hibernate.properties
file and via programmatic 3 configuration (more specifically, see Hibernate Reference Documentation, chapter 2 1 and 2. Here is an simple example, how 1 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
You'd have to need the driver (I don't know 6 if the jars you have are sufficient, but 5 it might be the case) on the classpath and 4 set the database dialect to org.hibernate.dialect.DB2Dialect
in your persistence.xml
.
In 3 JBoss it's normally only necessary to either 2 put the driver into the server's lib directory 1 or into the application's lib dir.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.