Ars
Ars

Reputation: 282

implement type 4 jdbc driver in DB2

In my project I'm using few configurations in context.xml and servlet.xml, where I'm setting

<ResourceLink 
     global="jdbc/mydatasource" 
     name="jdbc/mydatasource" 
     type="javax.sql.DataSource" />

<Resource 
     name="jdbc/mydatasource"
     auth="Container"
     type="javax.sql.DataSource"
     username=" DATABASE_USERNAME"
     password=" DATABASE_PASSWORD"
     driverClassName="com.ibm.db2.jcc.DB2Driver"
     url="jdbc:db2://IP:port/DBname" />

and using it in my servlet by including it through

 datasource = (DataSource) envContext.lookup("jdbc/mydatasource");

But I want to know what type of driver (type 2, 4, etc). I've imported db2jcc.jar in the application.

Upvotes: 0

Views: 3916

Answers (3)

Kristen Gillard
Kristen Gillard

Reputation: 21

The URL is incorrect actually:

For Type4:

  • jdbc:db2://server:port/database
  • jdbc:db2://server/database

Missing another colon.

Upvotes: 0

Mark Rotteveel
Mark Rotteveel

Reputation: 108939

Googling for DB2 type 4 driver gives me this page of IBM: Understand the DB2 UDB JDBC Universal Driver (from 2005). Reading this makes clear that db2jcc.jar is the universal driver, which is both a Type 2 and a Type 4 driver. What you use depends on the JDBC url you specify:

For Type 4:

  • jdbc:db2//server:port/database
  • jdbc:db2//server/database

For Type 2:

  • jdbc:db2:database

Be aware that - according to this site - you will also need db2jcc_license_cu.jar on your classpath to get the Type 4 driver to work.

Upvotes: 3

bhamby
bhamby

Reputation: 15440

Java has the DatabaseMetaData interface, which may have the information you are looking for. I'm not a Java person, but getDriverMajorVersion() may return what you're looking for.

Upvotes: 0

Related Questions