jQuery in Action, 3rd edition
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


Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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: 43417
    
  32
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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 32328
    
213

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


[OCA 8 book] [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
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3740
    
  10

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]
 
Don't get me started about those stupid light bulbs.
 
subject: Stored Procedure Problem
 
It's not a secret anymore!