我试图获取empid

时间:2017-03-18 15:55:20

标签: html mysql jsp servlets

这是我的问题,我试图从jsp获取数据,但每次我得到数字格式异常,任何人帮助我,我使用mysql作为数据库,我使用xamp作为编辑器

<pre>



@WebServlet("/Employee_Insert")
public class Employee_Insert extends HttpServlet {
    private static final long serialVersionUID = 1L;


    public Employee_Insert() {
        super();

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html");
        String btn=request.getParameter("submit");

        String Empid=" ";
        String empname=" ";
        String empcity=" ";
        String empdepartment=" ";
        String empsalary=" ";

        try
            {
                PrintWriter out=response.getWriter();
                Class.forName("com.mysql.jdbc.Driver");

                Connection con=DriverManager.getConnection("jdbc:mysql://localhost/practise","root","");

                if(btn.equals("INSERT"))
                    {
                        Empid=request.getParameter("Empid");
                        empname=request.getParameter("Empname");
                        empcity=request.getParameter("Empcity");
                        empdepartment=request.getParameter("Empdepartment");
                        empsalary=request.getParameter("Empsalary");


                    PreparedStatement ps=con.prepareStatement("insert into employee values(?,?,?,?,?)");
                        ps.setInt(1,Integer.parseInt(Empid));
                        ps.setString(2,empname);
                        ps.setString(3,empcity);
                        ps.setString(4,empdepartment);
                        ps.setDouble(5,Double.parseDouble(empsalary));

                        ps.executeUpdate();

0 个答案:

没有答案