File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes problem while insert date data in mysql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem while insert date data in mysql" Watch "problem while insert date data in mysql" New topic
Author

problem while insert date data in mysql

padma patil
Ranch Hand

Joined: Nov 06, 2001
Posts: 41
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

Joined: Mar 25, 2002
Posts: 264
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

Joined: Mar 25, 2002
Posts: 264
sorry just now i said to sqlserver...
just put curdate()...
inserrt into mysql values(curdate(),curdate())
padma patil
Ranch Hand

Joined: Nov 06, 2001
Posts: 41
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

Joined: Jul 09, 2001
Posts: 1879

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

Joined: Nov 06, 2001
Posts: 41
Hi,
Thanks.
Now My program works with PreparedStatement.
-
padma
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem while insert date data in mysql
 
Similar Threads
Connect to MySQL data base
this code not compiling! why?
returning a result set
JDBC:ODBC Oracle Connection
can't find jdbc driver