What is the DB2 jdbc driver or where can I get it from?

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.?


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.

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.

instead of adding maven dependency, add jar directly to tomcat/lib


      <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"/>

Direct connection from code

public class DB2Connection {
    static {
        try {            
        } catch (Exception e) {

    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();


        } catch (Exception e) {

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

official Link of DB 2 JDBC Driver from IBM

An official / supported DB2 java driver (Type 4 JDBC connector) is now (really for real) in maven central:


Include it as a dependency like so:

<!-- https://mvnrepository.com/artifact/com.ibm.db2/jcc -->

Need Your Help

Junit - run set up method once

java junit

I set up a class with a couple of tests and rather than using @Before I would like to have a setup method that executes only once before all tests. Is that possible with Junit 4.8?

incompatible character encodings: UTF-8 and ASCII-8BIT SQL Server

utf-8 sql-server-2014

My environment: Rails 4.2.4 Ruby 2.0 &amp; SQL Server 2014 with a collation of SQL_Latin1_General_CP1_CI_AS at the database level.