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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:22:19+00:00 2026-06-17T14:22:19+00:00

One of the fields which I extract from a database is a date in

  • 0

One of the fields which I extract from a database is a date in string format and I need to convert it into a date type to compare with another date.

How do I do this please? Everything I have tried so far gives me an error of java.util.Date cannot be cast to java.sql.Date and this is attempting the following example;

simpledateformat-gives-java-lang-classcastexception-java-util-date

An example of the date extracted in string format is “2012-10-15 09:00:29.157”. I think the format to declare is yyyy-MM-dd HH:mm:ss.SSS but not sure.

Thanks

  • 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-17T14:22:20+00:00Added an answer on June 17, 2026 at 2:22 pm

    It simply means you are assigning java.util.Date in java.sql.Date

    From your example you have to do following :

    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    java.util.Date date = (java.util.Date)formatter.parse(""2012-10-15 09:00:29.157"");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've a string which contains many fields I'd like to extract from it. These
I have a table in database that is having some fields one of which
I am running this query which selects a few fields from one table and
I created one app for database which contains a student table and 3 fields
I have a database from which I am trying to extract certain information. The
does there exist a universal database backup/extract format? I'll explain where I'm coming from:
I'm working with a database, where one of the fields I extract is something
I have a structure which has 3 identifier fields and one value field. I
I have a categories table, which one of the fields serves as the foreign
I have one table, t1, which has fileds called userid, week and year fields.

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.