0

I am getting the date (SettlementDate) in form of string in a method parameter as shown in the below method

   public List<abc> eee(Long Id,
                String sfsdf, boolean dfds,
                 String SettlementDate,
                ) {

now I am applying criteria as shown below but in pojo to which I am applying criteria IN THAT POJO THAT FIELD (SettlementDate) is of Date type as shown below

class ddd
{
private Date settlementDate;
}

below is the criteria implemetation

Criteria query = session.createCriteria(ddd.class);
query.add(Restrictions.eq("Id", Id));
query.add(Restrictions.eq("sfsdf", sfsdf));
query.add(Restrictions.eq("settlementDate", SettlementDate );

ultimately in database i want to store the date in this format 22.07.2016 00:00:00

now please advise how how do i set this value in criteria as rite now I am getting class cast exception in the below line

query.add(Restrictions.eq("settlementDate", SettlementDate );

which clearly proves that date of string type is not converted in date format ( 22.07.2016 00:00:00) folks , if I have to use simple date format then please advise how to use that in this situation ,Thanks

7
  • A date does not have a format. Commented Mar 20, 2014 at 15:07
  • @SotiriosDelimanolis date i want to store in this format 22.07.2016 00:00:00 Commented Mar 20, 2014 at 15:08
  • A date does not have a format. You're not storing a format, you're storing a date. Commented Mar 20, 2014 at 15:08
  • @SotiriosDelimanolis agree can you please advise , how can I convert the date from string type to date data type Commented Mar 20, 2014 at 15:10
  • You only have to use SimpleDateFormat. Commented Mar 20, 2014 at 15:11

1 Answer 1

1

If I understand it correctly, you want convert a date string to a date. You can try this:

query.add(Restrictions.eq("settlementDate", new SimpleDateFormat("dd.MM.yyyy hh:mm:ss").parse(SettlementDate)));

Some other remarks:

  • When storing a date in a db, you should use a Date or DateTime format, or maybe a Number containing the millisecs, but definately not a String
  • Java classes should start with a capital
  • Variable and parameter names should start with a lowercase letter
Sign up to request clarification or add additional context in comments.

1 Comment

@Fortega i tnk you have miss one bracket as it is giving compliation errors

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.