File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Stored Procedure Problem 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 "Stored Procedure Problem" Watch "Stored Procedure Problem" New topic

Stored Procedure Problem

payal Jain
Ranch Hand

Joined: Dec 20, 2007
Posts: 50
i have a stored Procedure
@name varchar(55)
@Date datetime
@News varchar(55)

RecordSet Returned:
Pacific News....
I am using jdbc to return the data from data base
Problem is i have to take out all the records of Current and the future date present in the database,how to apply this condition in jdbc.
please help me out with this as I am new to Stored procedure.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46337
Please show us what you have got so far.

Do you mean you want news from the future, or are you passing some date in the past?
What does the @ before the parameters mean?
payal Jain
Ranch Hand

Joined: Dec 20, 2007
Posts: 50
Actully that's what I have got from my DBA.Result of the prosedure should be same as the Query would be -select * from tablename where date>TodaysDate.So how to do this with that stored procedure.
My Java Cod till what I have done is
CallableStatement cs = con.prepareCall("{call getInfo(?,?)}");
cs.setString(2,Date That is already in Databse say"24-Dec-2008");
ResultSet rs=cs.executeQuery();
This thing gives me the record of the date that is already in database.
If I change the statement to
It give null result...
So How to do that???
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

Databases are picky with the format of dates when you use cs.setString(). It's highly unlikely that date.toString matches the format your database wants. Better is to use:
cs.setDate(2, theActualDateObject);

[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
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3753

That's one of the advantages of JDBC drivers + Prepared/Callable statements over straight SQL code in java, they can handle complicated issues like formatting for you! The second (or perhaps first) is that they are resilient to SQL injection attacks.

[OCA 8 Book] [Blog]
I agree. Here's the link:
subject: Stored Procedure Problem
It's not a secret anymore!