inserting an httpservletrequest object into a database date fiel

Discussions

Web tier: servlets, JSP, Web frameworks: inserting an httpservletrequest object into a database date fiel

  1. i do the following and I get a syntax error stating that i cant convert from string to date?

    pstmt.setDate(6,(java.sql.Date)request.getParameter("T"));

    I do the following and i cant convert to an integer?

    pstmt.setInt(10,(Integer)request.getParameter("X"));
  2. Bob
    You need to convert the string object to a date before using pstmt.setDate or setInt method.

    (eg)
    java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat(fmtstr);
    //fmtstr = "dd/MM/yyyy"

    java.util.Date dt = fmt.parse(request.getParameter("T"));


    Similarly you must use Integer.parse(request.getParameter("X")); method before using setInt method.

    Hope this helps.