Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem while insert date data in mysql

 
padma patil
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am facing folowing problem while inserting data into mysql table
mysql table is
Create table MyDate(Date Date, MyDate DateTime)

These record I have added manuly.
When I try to add record through Java it put 00 into all fields. Here is java code

=====================
Now result is
C:\Padmashree\working>java MyTime
2002-40-04 18:40:37
Thu Apr 04 18:40:37 CST 2002


What is happening here?
Do i need to convert Java date type to mySql Date type ? is then how?
Any help greately appreciated.
-
padma
[ Edited by Dave to format code ]
[ April 04, 2002: Message edited by: David O'Meara ]
 
Graham Thorpe
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why don`t u insert directly current date in ur datatbase like "insert into mysql values(getdate())"
then u get tge out putlike date format ..
try this one if not understabdf mail me
 
Graham Thorpe
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry just now i said to sqlserver...
just put curdate()...
inserrt into mysql values(curdate(),curdate())
 
padma patil
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have to insert date and time data into mysql database through java prpgram.curDate() method works for mqsql but not in java program.
Realy appreciate if anyone solve this problem.
-
padma
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use prepared statements to deal with inserting/updating dates. This way you can separate the formatting from the SQL update.
Changed code:

Jamie
 
padma patil
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks.
Now My program works with PreparedStatement.
-
padma
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic