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

  • Home
  • SEARCH
  • 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 3431886
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:22:53+00:00 2026-05-18T07:22:53+00:00

I need to convert a String like 2010-11-28 into Date type to be saved

  • 0

I need to convert a String like 2010-11-28 into Date type to be saved in a PostgreSQL database. I tried this code but when I check the result in a database both dates are null:

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date validStartDate=null;
Date validEndDate=null;

    try {
        validStartDate = df.parse(startDate);
        validEndDate = df.parse(endDate);

    } catch (Exception e) {

      ...

    }

    Assigment a  = new Assignment(..., validStartDate, validEndDate);
    session.save(s);

——————————–Edit—————————-

startDate and endDate are Strings in a format yyyy-mm-dd like 2010-11-27. There is nothing in the stack trace (the conversion seems to somehow work). If there was something I would probably know what is wrong. After conversion the dates are stored in a postgres database. Yes, I used util.Date instead of sql.Date (probably that’s a first mistake).

——————————- Edit2—————————

The code is simplified but: the stack trace doesn’t show anything strange, validStartDate and validEndDate are converted to something like this Tue Nov 30 00:00:00 CET (so not null). The Assignment is indeed correctly saved in a database. The sql: insert into public.assignment (type, valid_start_date, valid_end_date, id) values (5, NULL, NULL, 2). I tried to use sql.Date but no success.

—————————-Assignment mapping—————–

<hibernate-mapping>
  <class name="model.Assignment" schema="public" table="assignment">
    <id name="id" type="int">
      <column name="id"/>
      <generator class="increment"/>
    </id>


    <property name="validStartDate" type="date">
            <column name="valid_start_date" length="13" />
        </property>
        <property name="validEndDate" type="date">
            <column name="valid_end_date" length="13" />
        </property>
        <property name="type" type="integer">
            <column name="type" />
        </property>

  </class>
</hibernate-mapping>

I’m using Hibernate to save user data. The String is created by a JQuery widget Datepicker. Does anyone know how to solve that problem? Thanks in advance for help.

  • 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-05-18T07:22:54+00:00Added an answer on May 18, 2026 at 7:22 am

    A few comments with questions:

    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    Date validStartDate=null;
    Date validEndDate=null;
    
    try {
        validStartDate = df.parse(startDate);
        validEndDate = df.parse(endDate);
    
    } catch (Exception e) {
        // are there any exceptions thrown and caught here?
    }
    
    // are validStartDate and validEndDate non-null at this point? 
    // is this code even executed? it won't be if an exception was thrown...
    Assigment a  = new Assignment(..., validStartDate, validEndDate);
    
    // where did this "s" come from? did you mean "session.save(a)"?
    session.save(s);
    

    Aside from these questions, you should check the following:

    Is Hibernate really saving your Assignment in database?

    Are your Hibernate mappings correct?

    Did you try using java.sql.date?

    What is the generated SQL? You can turn that option on by using <property name="show_sql">true</property> in your hibernate.cfg.xml file.

    Only by checking all of above will you be able to solve your problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an xml document object that I need to convert into a string.
I need to convert from a SQLVARCHAR to a string data type Variable definitions
I have a string I need to convert back to a date. I can
I need a PHP version of the following C# code: string dateSince = 2010-02-01;
I am working on a tool where I need to convert string values to
Let's say I have an integer that I need to convert to a string
I have a string that I need to convert to the equivalent array of
Given a string as below, I need to convert: 1 Dec 2008 06:43:00 +0100
i need a Regular Expression to convert a a string to a link.i wrote
I need to convert strings with optional trailing signs into actual numbers using Powershell.

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.