| 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: 1318
|
|
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..
[Linkedin] How To Ask Questions On JavaRanch My OpenSource
|
 |
Adeel Ansari
Ranch Hand
Joined: Aug 15, 2004
Posts: 2874
|
|
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.
|
 |
 |
|
|
subject: sql exception when try to get date
|
|
|