• Post Reply Bookmark Topic Watch Topic
  • New Topic

Type 2 and Type 4 Drivers for DB2

 
Vinu krish
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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 COM.ibm.db2.jdbc.app.DB2Driver (Type 2 ) . Code snippet is as follows

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

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 com.ibm.db2.jcc.DB2Driver (Type 4) to connect to the database.
Can someone tell me if the problem is due to driver?

Thanks,
Vinu
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36007
422
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vinu,
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.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!