Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7990711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:05:41+00:00 2026-06-04T13:05:41+00:00

I am developing a Spring/Hibernate web application. I have a DataTranseferObject where the input

  • 0

I am developing a Spring/Hibernate web application. I have a DataTranseferObject where the input from the jsp page is stored to be used by different services and eventually saved to a database.

One of the fields in the jsp page is deliveryDate. I want to store it as a date type in the database:

from delivery.java

@Column(name = "DELIVERY_DATE") 
private Date deliveryDate; 

public void setDeliveryDate(Date deliveryDate){
    this.deliveryDate= deliveryDate;
}
public Date getDeliveryDate(){
    return deliveryDate;
}  

I am trying to validate the field in the jsp page so that only the "yyyy-MM-dd" format is allowed. To do this I have the deliveryDate as a String type in the DataTransferObject and I’m validating it with the @Pattern annotation as such:

@Pattern(regexp="((19|20)\\d\\d)-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])", message="please enter date in fromat yyyy-MM-dd")
@NotNull(message="delivery date is a required field")
private String deliveryDate;

Since I want to store it in the database as a Date type I need to convert the String to a Date type. This I am trying to do using a service:

@Transactional
public Date stringToDateConversion(String stringDate){

    DateFormat formatter;
    Date date;
    formatter = new SimpleDateFormat("yyyy-MM-dd");
    date = (Date) formatter.parse(stringDate);
    return date;
}

but it’s not working since formatter.parse(stringDate) gives "Unhandled exception type ParseException"

I need the service to return a Date type so I can use it in the controller:

    Date deliveryDate= deliveryService.stringToDateConversion(deliveryDto.getDeliveryDate());
    delivery.setDeliveryDate(deliveryDate);

How do I correctly convert the String to a Date type and return a Date type?

Thanks for the help!
/D

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:05:42+00:00Added an answer on June 4, 2026 at 1:05 pm

    Just handle ParseException with call of parsing String to Date

    DateFormat formatter =  null;
    java.util.Date date = null;
    formatter = new SimpleDateFormat("yyyy-MM-dd");
    try{
      date = formatter.parse(stringDate);
      //if you want you can convert it to `java.sql.Date`
    }catch(ParseException ex){//do whatever you would like to}
    
    return date;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Spring Web MVC and Hibernate for developing my application. My login.jsp
I am developing a Java Web Application using JSF, Spring and Hibernate. I need
We are developing a web application using Spring framework and Hibernate ORM. As far
I'm developing a web application on Apache Tomcat 6 with Hibernate and Spring, I'm
I am developing my first Java web application (Spring/Hibernate/Freemarker) and my only concern is
I am developing a new web application with Struts2, Spring and Hibernate as its
I'm developing a web application based on JPA + Hibernate, Spring and Wicket. I
I'm developing a web application with multiple frameworks (spring, hibernate, spring-security, ZK for GUI),
I'm developing a web application based on Hibernate, Spring and Wicket. Until now I
I'm developing an example web-application, using JPA 2.0 entities, Hibernate 3.6.2 and Spring 3.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.