Exception with date formatter
I've the below code in my jsp.
- <%@page import="java.util.Date"%><%@page import="java.util.*,java.text.*" %><%@include file="DBCon.jsp" %><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Insert title here</title></head><body><%try{SimpleDateFormat formater = new SimpleDateFormat("d-MM-yyy");String a=request.getParameter("sid");String b=request.getParameter("desc");String c=request.getParameter("pubcode");String d=request.getParameter("ProdType");Date e=formater.parse(request.getParameter("DateRec"));String f=request.getParameter("TimeRec");String g=request.getParameter("Units");Date h=formater.parse(request.getParameter("VWR"));Date i=formater.parse(request.getParameter("AEDue"));Date j=formater.parse(request.getParameter("AsByDate"));String k=request.getParameter("SerID");/* String sql="insert into Welcome_Page (SHIPMENT_ID_/_IDS, PRODUCT_CODE, PRODUCT_NAME, PRODUCT_TYPE, UNIT_COUNT, RECEIVED_DATE, RECEIVED_TIME, VWR_DUE_DATE, AE_DUE_DATE, ASSIGN_BY_DATE,SERIAL_NUMBER) values (?,?,?,?,?,?,?,?,?,?,?)"; */String sql="insert into Welcome_Page(SHIPMENT_ID_/_IDS, PRODUCT_CODE, PRODUCT_NAME, PRODUCT_TYPE, UNIT_COUNT, RECEIVED_DATE, RECEIVED_TIME, VWR_DUE_DATE, AE_DUE_DATE, ASSIGN_BY_DATE,SERIAL_NUMBER) values ("+a+", '"+c+"', "+b+", '"+d+"', "+g+", str_'"+e+"', '"+f+"', '"+h+"', '"+i+"', '"+j+"', "+k+")";//ps=con.prepareStatement(sql);/* ps.setString(1,a);ps.setString(2,c);ps.setString(3,b);ps.setString(4,d);ps.setString(5,g);ps.setString(6,e);ps.setString(7,f);ps.setString(8,h);ps.setString(9,i);ps.setString(10,j);ps.setString(11,k); */ out.println(sql); /* ps.executeQuery();con.commit(); */ }catch(Exception e){ out.println(e);}%></body></html>
- here when i change
SimpleDateFormat formater = new SimpleDateFormat("d-MM-yyy");
to
SimpleDateFormat formater = new SimpleDateFormat("dd-MM-yy:HH:mm:SS");
. I'm getting the below Exception.
- java.text.ParseException: Unparseable date: "09-02-14"
- If i leave it as it is i'm getting the below query.
- insert into Welcome_Page(SHIPMENT_ID_/_IDS, PRODUCT_CODE, PRODUCT_NAME, PRODUCT_TYPE, UNIT_COUNT, RECEIVED_DATE, RECEIVED_TIME, VWR_DUE_DATE, AE_DUE_DATE, ASSIGN_BY_DATE,SERIAL_NUMBER) values (12, 'adfsf', 234234, 'Looseleaf - Update', 234234, str_'Fri Feb 09 00:00:00 IST 14', '43', 'Fri Mar 09 00:00:00 IST 14', 'Fri Aug 09 00:00:00 IST 15', 'Fri Nov 09 00:00:00 IST 14', 242)here i actually have a jquery date picker in my main html file and i want to insert the date selected there to my database.
please let me know where i'm going wrong and also how to fix it.
Thanks