Two Laptop Bag
The moose likes JDBC and Relational Databases and the fly likes Type 2 and Type 4 Drivers for DB2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Type 2 and Type 4 Drivers for DB2" Watch "Type 2 and Type 4 Drivers for DB2" New topic

Type 2 and Type 4 Drivers for DB2

Vinu krish

Joined: Nov 20, 2003
Posts: 16
There is a stored procedure in DB2 which expects Date as its input parameter. The code is deployed in weblogic 8.0 and the driver used is (Type 2 ) . Code snippet is as follows

CallableStatement CS = conn.prepareCall(SQL(?));
String strdate = "2005-01-01";
CS.setString(1, strdate)

When i run the same piece of code in my local IDE (WSAD) , i get the following error
DB2 SQL error: SQLCODE: -301, SQLSTATE: 42895, SQLERRMC: 005;

SQLState 42895 is due to "For static SQL, an input host variable cannot be used, because its data type is not compatible with"

Hence I changed the statement from CS.setString(1, strdate) to
CS.setDate(1, java.sql.Date()) and it worked fine. The only difference I could see is that my IDE uses (Type 4) to connect to the database.
Can someone tell me if the problem is due to driver?

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

The format of dates is very database and driver specific. So it is perfectly believe that the driver is the difference. Note that it is better practice to use setDate() anyway.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Type 2 and Type 4 Drivers for DB2
It's not a secret anymore!