java - Unknown column 'jay' in 'field list' -
i trying insert values id(not auto incr), eid, ename, esalary, eaddress mysql table named employee following exception showed
java.sql.sqlexception: unknown column 'jay' in 'field list'
1. insert.jsp
<form method="post" action="insertbackend.jsp"> <table border="1"> <tr> <td style="font-size:20px ">enter employee id: </td> <td><input type="text" name="id" /></td> </tr> <tr> <td style="font-size:20px ">enter employee name: </td> <td><input type="text" name="en" /></td> </tr> <tr> <td style="font-size:20px ">enter employee salary: </td> <td><input type="text" name="es" /></td> </tr> <tr> <td style="font-size:20px ">enter employee address: </td> <td><input type="text" name="ea" /></td> </tr> <tr> <td style="border-right:0em;"></td> <td style="border-left:0em;"><input type="submit" value="insert"></td> </tr> </table> </form>
2. insetbackend.jsp
<% try { string eid=(string)request.getparameter("id"); string en=(string)request.getparameter("en"); string es=(string)request.getparameter("es"); string ea=(string)request.getparameter("ea"); class.forname("com.mysql.jdbc.driver"); connection c=drivermanager.getconnection("jdbc:mysql://localhost:3306/test","root","root"); statement s=c.createstatement(); s.executeupdate("insert employee values("+eid+","+en+","+es+","+ea+")"); c.close(); s.close(); } catch(exception e) { out.println(e); } %>
edit line:
s.executeupdate("insert employee values("+eid+","+en+","+es+","+ea+")");
in to:
s.executeupdate("insert employee values('"+eid+"','"+en+"','"+es+"','"+ea+"')");
since using strings, must add quotes surrounded..
Comments
Post a Comment