im updating a table on database with SQLPlus from a JSP page with name and Date of birth, how to insert the date of birth in Date format ? Please help me.
String dob=request.getParameter("DOB");
SimpleDateFormat formater = new SimpleDateFormat("dd-MM-yyyy");
Date result = formater.parse(dob);
stmt.executeUpdate("INSERT INTO table(DOB)VALUES('"+result+"')");
and my variable type in table is “Date”.
You’re not using sqlplus here. You’re using JDBC.
And a date is a date. It’s not a String. Sqlplus shows you the date as a string formatted in a certain way to make it readable, but you shouldn’t transform dates into strings to store them. Use a PreparedStatement:
PreparedStatement should always be used to pass dynamic parameters to a SQL query. It’s safer, more robust, and avoid SQL injection attacks.
Read the JDBC tutorial about prepared statements.