• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

GregorianCalendar to string and back to Date

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Water! People swim in water! Even tiny ads swim in water:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic