Reputation: 331
Hello guys I want to ask a few things for DB2 Hibernate configuration. I searched it google, but I couldn't find.First of all,I want to get Maven dependency of DB2 JDBC driver.And then Which dialet class I need to use.?
Upvotes: 3
Views: 17798
Reputation: 1280
An official / supported DB2 java driver (Type 4 JDBC connector) is now (really for real) in maven central:
https://mvnrepository.com/artifact/com.ibm.db2/jcc
Include it as a dependency like so:
<!-- https://mvnrepository.com/artifact/com.ibm.db2/jcc -->
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>jcc</artifactId>
<version>11.1.4.4</version>
</dependency>
Upvotes: 3
Reputation: 2063
instead of adding maven dependency, add jar directly to tomcat/lib
configuration:
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:db2://localhost:50000/dbname"/>
<property name="javax.persistence.jdbc.password" value="root"/>
<property name="javax.persistence.jdbc.driver" value="com.ibm.db2.jcc.DB2Driver"/>
<property name="javax.persistence.jdbc.user" value="root"/>
</properties>
Direct connection from code
public class DB2Connection {
static {
try {
Class.forName("com.ibm.db2.jcc.DB2Driver");
} catch (Exception e) {
System.out.println("Error");
e.printStackTrace();
}
}
public static void main(String argv[]) {
try {
Connection con = null;
String url = "jdbc:db2://localhost:50000/dbname";
String userid = "root";
String passwd = "root";
con = DriverManager.getConnection(url, userid, passwd);
System.out.println("Connected " + con);
Statement stmt = con.createStatement();
}
//rs.close();
stmt.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Upvotes: 1
Reputation: 4599
You can not find a public repository that serves dependencies for DB2 due to copyright issues. You have to download the zip file that contains the jar files as imran tariq described and then you have to install them to your local repository using mvn install
command. You can read more about maven install here.
You can read about how to deploy the db2 jars to your local or remote repository here.
Upvotes: 4
Reputation: 7693
I am not sure you can get an official IBM DB2 driver from Maven central. I think it is just because the license. IBM driver is propietary software with its own license and distribution rights (yes, when you click over I agree at download time). Maven repository has its own rules to distribute the software, and probably these rules are agaist IBM politics.
Maven central is for free distribution software, most of that software is open source, instead DB2 drivers are not open source software. However, DB2 Express-C is "free" to distribute, but I am not sure if the dirvers are part of that "free", and I do not know what are the boundaries of that distribution.
Probably, IBM has its own Maven repository, as jBoss has, but I have never heard about that. If not, it could be a good initiative.
I think you should contact IBM (DB2 express-c forum in developerWorks) in order to know how to get the drivers from Maven, or simply, if you can upload them there as a new project or somethign similar.
Upvotes: 4
Reputation: 23352
DB2 JDBC driver are used to connect from JAVA application to DB2. After connection you can do CRUD operation from your application.
You can get the drivers from the IBM site. You will need to have IBM ID and password to login (which you can obtain here). Zip file is about 7 MBs, in contains DB2 9.5 JDBC (type 2/4) and SQLJ drivers. Type 4 drivers are in db2jcc4.jar. However, you won't be able to connect to mainframes with this driver if mainframe is running DB2 for z/OS. To do so, you need at least to purchase DB2 Connect product, which will cost you about $500 minimum.
You will use DB2 dialect
<prop key="hibernate.dialect">org.hibernate.dialect.DB2Dialect</prop>
Refer Here
Upvotes: 0