1

How do I get the following code to work?

String d=request.getParameter("bday");

GET parameter is null value but i m storing here html datepicker, even though I'm passing a value

Extra_User.jsp

<html>
<body>
<form name="frm1" method="post" action="Extra_User_Data.jsp">
<font size="4">Birthday<td><input type="date" id="bday">
</form>
</body>
</html>

Extra_User_Data.jsp

<%@page import="java.sql.*"%>
<%
try
{
String d=request.getParameter("bday");

        Connection cn;
        Statement st;

Class.forName("com.mysql.jdbc.Driver");
                cn=DriverManager.getConnection("jdbc:mysql://localhost:3306/main","root","");
st=cn.createStatement();
st.executeUpdate("INSERT INTO newuser(dob)VALUES('"+d+"')");                
out.println("Insert SuccessFull");
    }

    catch(SQLException sq)
    {
        out.println(sq.toString());
    }
%>

I am passing some date from html form to another .jsp file but while adding data in data base its shows null value.

it's shows error like...

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect date value: 'null' for column 'dob' at row 1

  • Welcome to [so]! This question has all of the [right stuff](https://stackoverflow.com/help/mcve), but some of it was hidden in the title. Please keep your title short, and repeat all relevant information in the question body, where you can use formatting to help make your point. – jpaugh Feb 27 '18 at 14:24

1 Answers1

0

Use name instead of id for your input

Nader
  • 96
  • 1
  • 7
  • Thank You...It's Working...!!! – Ajay Purohit Feb 27 '18 at 12:42
  • Good catch! Remember that a question worth answering is also worth up-voting. (This question turned out to be a duplicate, but it's still great way for someone to search and find the [canonical question](https://stackoverflow.com/q/1397592/712526).) – jpaugh Feb 27 '18 at 14:31