| Author |
DB2 query cannot work using preparedstatement
|
vivien siu
Ranch Hand
Joined: Nov 10, 2005
Posts: 143
|
|
hi, I'm trying to pass in a string object into the PreparedStatement below: This is the exception I got:
com.ibm.db2.jcc.b.SQLException: The value of input host variable or parameter number "1" cannot be used because of its data type.
The query will smoothly if I use Statement object instead. Please let me know what is wrong with using PreparedStatement?
|
I'm not available, my BF's name is WORK.
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26201
|
|
One of the big advantages of using Prepared Statements is not to have to worry about date formats and casting. If you really want to use it, see what type the cast function is expecting. This query could be written as: where date between ? and ?. This may be more efficient as the database doesn't need to run functions for every single row.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
vivien siu
Ranch Hand
Joined: Nov 10, 2005
Posts: 143
|
|
I want to select the values where condition will be "drundate"(value from db2) = a certain date. however the "drundate" inside the database is a timestamp. I only need to compare the date value and not the whole timestamp. how can I pass in a string then cast it to a date object correctly?
|
 |
Adeel Ansari
Ranch Hand
Joined: Aug 15, 2004
Posts: 2874
|
|
There are a few ways. - Use database specific function to format your timestamp into date - split your condition into two like less than <late-day-timestamp> and greater than <early-day-timestamp> [ April 26, 2006: Message edited by: Adeel Ansari ]
|
 |
 |
|
|
subject: DB2 query cannot work using preparedstatement
|
|
|