• 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

Wildcard value and PreparedStatement

 
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. I am using a PreparedStatement for an order search class I am creating. I want to query a datetime field in one of my tables. If I key the statement "SELECT * FROM ORDERMASTER WHERE ActualShipDate = '%'" it works great. However, since I am using a PreparedStatement, I have to set this parameter using setDate(). Correct? How can I set this value to a wildcard character (%) if it is looking for a value of the date type?
Any help would be GREATLY appreciated!!
 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should be able to use the setString() method instead. If the query you listed above executes successfully from a sql editor, then that should work.
I'm sure it depends on the db vendor, but for ours (Informix), we can always use setString() regardless of the datatype and the db will interpret it appropriately.
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help. That worked.
Now I have another question. Here is my PreparedStatement:


I have everything working the way I want it for this search I am creating except for setting the parameter for the Actual Ship date.
The user can select the option to search for shipped and unshipped orders (which is where I used the wildcard character) and that works. They can also choose to just search only shipped orders, or only unshipped orders. This is where I am running into problems.
What do I set the parameter to, to weed out the records with valid ship dates? I am using a default date of 1900-01-01 in unshipped orders so I can't use null. I can't use the wildcard character because that will still bring back all of them.
Also, can I not use the LIKE keyword with any other value than the wildcard on a DateTime field? I do not get any results if I key in "1900%".
Any suggestions?
Thanks!
[ October 07, 2002: Message edited by: Jennifer Sohl ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic