Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
  • Carey Brown
  • salvin francis
  • Claude Moore

parse String to sqlDate  RSS feed

Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i try withthe snippet of code when i try to format a String to sql date and to insert the date into table of database with one column with name dateep:

when i executed it generate this error :Exception in thread "main" java.sql.SQLDataException: ORA-01861: literal does not match format string
please how can i solve the problem of inserting date into oracle database ofter parsing from string
Saloon Keeper
Posts: 10128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's because after parsing the date, you're converting it back to a string again when you concatenate it to your insert statement. The resulting SQL query will look like this:

This apparently isn't what your database expects DATE values to be formatted like.

You shouldn't be manually hacking your queries together anyway. Use a prepared statement. Also, avoid java.util.Date and use the new java.time API instead, before you convert it to java.sql.Date. Finally, don't forget to close your connections.
They gave me pumpkin ice cream. It was not pumpkin pie ice cream. Wiping my tongue on this tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!