wood burning stoves 2.0*
The moose likes JDBC and the fly likes sql exception when try to get date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "sql exception when try to get date" Watch "sql exception when try to get date" New topic
Author

sql exception when try to get date

palmari sivasubramanian
Greenhorn

Joined: Mar 07, 2006
Posts: 6
Hi all,

I have created on html page to get Date of Birth.In jsp page,
String d=request.getParameter("day");
String m=request.getParameter("month");
String y=request.getParameter("year");
String dob=d+"/"+m+"/"+y;

In my table(app) i have given dob as one column and declared as DATE Type.

in JDBC,
i have used this statement
stmt.executeUpdate("insert into app values(TO_DATE('dob','dd/mm/yyyy'))");

it is not updating in my database. if i give sysdate, it is updating in the database.What is the problem in this? is the way of approch, correct to update the date in my database? help me out.

Thanks in advance
Palmari.
Mateus Lucio
Ranch Hand

Joined: Jul 27, 2006
Posts: 57
most Databases use english Date format
try this
stmt.executeUpdate("insert into app values(TO_DATE('dob','mm/dd/yyyy'))");

just a guess though


Studying ...
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

Hi palmari sivasubramanian,

Welcome to Java Ranch

To insert date values into database, you should use java.sql.Date .

String dob = d+"/" + m+ "/" + y;
SimpleDateFormat sdf = new SImpleDateFormat("dd/MM/yyyy");
java.util.Date javaDate = sdf.parse(dob);
java.sql.Date sqlDate = new java.sql.Date(javaDate);


SimpleDateFormat (Java 2 Platform SE 5.0)
[ August 12, 2006: Message edited by: Saif Uddin ]

Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Saif Uddin:
String dob = d+"/" + m+ "/" + y;
SimpleDateFormat sdf = new SImpleDateFormat("dd/MM/yyyy");
java.util.Date javaDate = sdf.parse(dob);
java.sql.Date sqlDate = new java.sql.Date(javaDate);


We dont have this very, java.sql.Date(java.Util.Date date), constructor. Use new java.sql.Date(javaDate.getTime()).
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Mateus Lucio:

stmt.executeUpdate("insert into app values(TO_DATE('dob','mm/dd/yyyy'))");


Use PreparedStatement instead.
 
wood burning stoves
 
subject: sql exception when try to get date
 
Similar Threads
how to generate sql date
not able to get values into database
concatenate Text Fields in JSP
Problem with datetime fields
Struts Date Conversion