File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC 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
Bookmark "Stored Procedure Problem" Watch "Stored Procedure Problem" New topic
Author

Stored Procedure Problem

payal Jain
Ranch Hand

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

)
RecordSet Returned:
SubmittedByPerson
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
Sheriff

Joined: Oct 13, 2005
Posts: 38793
    
  23
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(1,null);
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
cs.setString(2,java.util.Date.toString);
It give null result...
So How to do that???
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30512
    
150

Payal,
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);


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

Joined: Oct 23, 2005
Posts: 3704
    
    5

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.


My Blog: Down Home Country Coding with Scott Selikoff
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stored Procedure Problem