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 6683237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:47:51+00:00 2026-05-26T04:47:51+00:00

The situation is something like this: PostgreSQL Database table has a field dateAdded which

  • 0

The situation is something like this:

PostgreSQL Database table has a field dateAdded which is timestamp

The Pojo Model object maps this field as

class MyModel{
   org.joda.time.DateTime dateAdded;

}

My Dao Implementation is in Spring JDBC Template and it goes as:

SqlParameterSource parameters = new BeanPropertySqlParameterSource(patient);
jdbcInsert.execute(parameters);

I read model from the client and build the object using @Model. Everything is fine so far. When I execute this, the database throws an exception saying:
[Edit Erwin]: Turns out the exception is not coming from the database.

org.postgresql.util.PSQLException: Bad value for type timestamp : 2011-10-10T21:55:19.790+03:00

I don’t want to do the formatting manually by implementing a full INSERT statement as there are many fields involved.

What is the best possible solution here? Is there a way to configure toString() of DateTime on all calls. I also thought about creating an inherited class from DateTime but … mmhh.. it’s a final.

—

Edit

Per Erwin, I tested DateTime value ‘2011-10-10T21:55:19.790+03:00’ by inserting into a dummy table and it’s working. But can’t get to work with JDBC. Something related to the JDBC driver?

  • 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-26T04:47:52+00:00Added an answer on May 26, 2026 at 4:47 am

    The problem here is that JdbcTemplate is using a prepared statement and then binding the values. The field in question is a of type timestamp – so it needs to be set as a java.sql.Date. In this case spring is calling the generic setObject method passing it the Joda Time DateTime instance. The driver doesn’t know how to convert this into a java.sql.Date – hence the error.

    To fix this problem you can extend BeanPropertySqlParameterSource override the getValue method. If the type of object is joda.time.DateTime convert it to a java.util.Date object and return it. That should fix the issue.

    class CustomBeanPropertySqlParameterSource extends BeanPropertySqlParameterSource {
      @Override
      Object getValue(String paramName) {
         Object result = super.getValue(paramName);
         if (result instanceof DateTime) {
            return ((DateTime) result).toDate();
         } else {
            return result;
         }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My situation is something like this: class AbstractClass: def __init__(self, property_a): self.property_a = property_a
The situation is something like this. There are three pages page1,page2,page 3 Situation Page1
I can't make git push origin B. I have situation something like this _____________________________________
Situation is a string that results in something like this: <p>This is some text
In a situation where you have something like a Lite, Normal, Ultimate tiers and
Situation: A PHP application with multiple installable modules creates a new table in database
Situation: Table TBL has ~10k entries for deletion, Table TBL has 14 child tables
The situation is this: You have a Hibernate context with an object graph that
I'd need advice on following situation with Oracle/PostgreSQL: I have a db table with
Situation Say I have the following: a table items a table lists to which

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.