• 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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

parse String to sqlDate  RSS feed

 
Ranch Hand
Posts: 45
  • 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: 9857
199
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!