• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DB2 query cannot work using preparedstatement

 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
vivien siu
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic