• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sql exception when try to get date

 
palmari sivasubramanian
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
most Databases use english Date format
try this
stmt.executeUpdate("insert into app values(TO_DATE('dob','mm/dd/yyyy'))");

just a guess though
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mateus Lucio:

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


Use PreparedStatement instead.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic