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

GregorianCalendar to string and back to Date

 
mangesh lele
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
I want to carry out validation on a GregorianCalendar instance to check if it is present in my database as a corresponding Oracle Date field
In the existing framework, the validation is done by a class which takes String argument and parses it to get a Date object (using DateFormat).
The class which calls the validation class gets the GregorianCalendar instance which is to be validated.
How can I pass a String representation of this GregorianCalendar instance to the validation class so that it can convert it back to an SQL Date object?
Sample Code:
The Validation class: -
.
.
.
.
.
public boolean checkAll(String iDate){
.
.
.
.
SimpleDateFormat sdfInput=new SimpleDateFormat("MM-dd-yyyy");

Date mDateValue = sdfInput.parse(iDate);
PreparedStatement lPreStatement.setDate(1,(java.sql.Date)mDateValue);
.
.
.
.
}

The Calling class: -
.
.
.
.
.
.
String lSomeDate; //to be populated with GregorianCalendar representation
boolean lbIsDatePresent = checkAll(lSomeDate);
.
.
.
.
Hope I havent made it too cryptic
Thanks in advance.
[ May 26, 2003: Message edited by: mangesh lele ]
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the Calendar's .getTime() method, which returns a java.util.Date representation of the Calendar.
I would even overload the checkAll method to accept a Date, so that you don't have to convert the Date to a String and then back to a Date.
[ May 26, 2003: Message edited by: Joel McNary ]
 
mangesh lele
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks joel
i know my requirement is a pretty roundabout way of doing things and could be made lot easier, but the thing is since i'm plugging validations into an existing framework, i have to stay within its constraints.
so my real problem is that the only message that can be passed from calling class to validation class is a String object, and hence needs to be converted back and forth.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic