Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stored Procedure Problem

 
payal Jain
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49776
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34839
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
 
Scott Selikoff
author
Saloon Keeper
Posts: 4020
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic