• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to add value in filed in data base having type as DateTime

 
Ranch Hand
Posts: 79
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
Greetings!

I have one database table having one column of type DateType.
I'm getting values for Date and time from a HTML page.

I want to add values to Database, I know to use setDate() function for Prepared Statemnt.
But I'm not clear for DateType field, As below:

prepState.setDate(3, Date.valueOf(aNewAppointment.getDateTime()));

But using the above statement i'm getting error "SEVERE: java.lang.IllegalArgumentException".
Anyone, Please help me on that. (Please find Table's Screenshot)

Thanks in Advance.
DataBase-Table.PNG
[Thumbnail for DataBase-Table.PNG]
Table Screenshot
 
Marshal
Posts: 79259
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
“TIMESTAMP”???
 
Gursewak Singh
Ranch Hand
Posts: 79
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In MySQL field data type is dateTime
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think Campbell is trying to suggest you use the type java.sql.Timestamp.

Also, try separating out the parts. I suspect the error is coming from:


So try putting that on a separate line:


If that is the problem, you can use SimpleDateFormat to create a java.util.Date object. Then you can convert it to a java.sql.Date or java.sql.Timestamp object. For example:
 
This tiny ad will self destruct in five seconds.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic