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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:53:11+00:00 2026-05-28T22:53:11+00:00

This is a simple question: I know and have heard from almost everyone that

  • 0

This is a simple question: I know and have heard from almost everyone that using java.util.Date for anything in a Jdbc call is a bad idea. You should use either java.sql.Date or java.sql.Time or java.sql.Timestamp. However, what is the reason not to? I can’t find a good blog post or SO post explaining it, except that sometimes people see “weird behavior”.

Thanks!

EDIT:

So, I have seen this post. Yeah, the only part of that post that sort of answers my question is

…to most JDBC drivers which will happily devour it as if it was of
the correct type but when you request the data afterwards, you may
notice that you’re actually missing stuff.

However, that doesn’t really answer why.

  • 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-28T22:53:12+00:00Added an answer on May 28, 2026 at 10:53 pm

    Okay, so having read all the information throughout the answers, and the others posts pointed to in comments and so forth, I’ve decided to summarize what I learned:

    The Setup:

    From what I can see, there are three layers

    JDBC wrapper calls (e.g. Spring's SimpleJdbcTemplate)
    |
    |
    Raw JDBC calls (e.g. PreparedStatement)
    |
    |
    JDBC driver (e.g. Oracle)
    

    The First Reason

    Many JDBC class wrappers, such as Spring’s famous SimpleJdbcTemplate, allowed you give it a Map<String, Object> as the argument map when executing a SQL statement. This is wonderfully simple, as it hands all the conversions from the objects to the proper java.sql.* types when it uses raw JDBC under the hood. The first problem is here: what happens if you have the following:

    Map<String, Object> paramMap = new HashMap<String,Object>();
    paramMap.put("p_some_data", new java.util.Date());
    

    What does Spring convert it to? A java.sql.Date? A java.sql.Timestamp? A java.sql.Time? Or does it even cast it to a java.lang.Object? As well explained by @BalusC in this answer to a different question and by another fellow here, there are big differences between those three java.sql types. So, that’s the first reason not to use java.util.Date: you can’t rely on the internal convention of a framework to handle the conversion for you.

    The Second Reason

    Now, talking about raw JDBC calls, @The Nail explained that you need these java.sql types to make JDBC calls, and he’s absolutely right, which was news to me. However, there is still the dreaded setObject call. From reading the JavaDoc for that call, it seems a little ambiguous as to what it will do if give a java.util.Date. So, the second reason not to use it is because of the ambiguity there.

    The Third Reason

    Finally, talking about the level of the driver. I can attest with personal experience that sometimes Spring in conjunction with the Oracle driver does work with java.util.Date. Sometimes. And then sometimes it doesn’t. So, because I have no clue how any particular version of any particular driver will handle a java.util.Date, it’s best to be explicit. This is the third reason.

    Conclusion

    In general, it looks like the reason is: “JDBC is not supposed to be used with java.util.Date. If you do, you cannot be sure what will happen.” This is a good enough reason for me 🙂

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

Sidebar

Related Questions

I know this is a simple question for someone out there, but I have
I know that this is a simple question for PHP guys but I don't
I know this is a darn simple question, but I'm very used to using
This should be a very simple question. I have a richfaces tree that is
This is a general question. Using an example below, suppose that I have a
I know this is a simple question, but I can't figure it out. Consider
This is a simple question and I am sure you C# Pros know it.
Alright, I know this is a simple question, but I can't seem to get
This is probably a simple question, but I really don't know what I'm doing
I know this is a really simple question but my google-fu is failing me.

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.