I use p:calender in dd/MM/yyyy format and want to store it in MySql as Date type in same dd/MM/yyyy format.But it gives me a parser exception and MySQL Data Truncation.
Do i need to use any date formatter to store it in Database.
.xhtml
Code: Select all
<p:calendar widgetVar="leaseExpirationDateTo"
onchange="validateDate(this);"
onfocus="jQuery('invoice_date.hasDatepicker').mask('99/99/9999');"
value="#{paymentbean.date}"
navigator="true" pattern="dd/MM/yyyy"
id="invoice_date">
</p:calendar>
Code: Select all
SimpleDateFormat sdf=new SimpleDateFormat("dd/MM/yyyy");
String sdate=sdf.format(date);
System.out.println(sdate);
SimpleDateFormat sdd=new SimpleDateFormat("dd/MM/yyyy");
Date d= sdf.parse(sdate);
System.out.println(d);
con.setAutoCommit(false);
System.out.println(date);
//String sql="insert into payment_header(payment_no,payment_date,remarks) values('"+payment_no+"','"+date+"','"+remarks+"')";
//stmt.executeUpdate(sql);
PreparedStatement pstmt=con.prepareStatement("insert into payment_header(payment_no,payment_date,remarks) values(?,?,?)");
pstmt.setString(1, payment_no);
pstmt.setDate(2,(java.sql.Date.valueOf(sdate)));
pstmt.setString(3, remarks);
pstmt.executeUpdate();