正在获取java.sql.SQLException:列数与第1行的值数不匹配

问题描述 投票:0回答:1

我正在使用JDBC创建网站,运行TOMCAT时出现以下错误,我该怎么办,我在MYSQL工作台中创建了6列,分别为uname,pass,name,city,email,phone,但仍然这个错误。

这是我的register.java servlet文件,我运行它并复制粘贴的类到WEB-INF / classes文件夹中

public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{
        response.setContentType("text/html");
            PrintWriter out=response.getWriter();
        try{
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/form","root","sudhakar");

            String uname = request.getParameter("uname");
            String psw = request.getParameter("psw");
            String nam = request.getParameter("nam");
            String cit = request.getParameter("cit");
            String ema = request.getParameter("ema");
            String num = request.getParameter("num");
                    PreparedStatement pst = con.prepareStatement("insert into login values(?,?,?,?,?,?)");
                    pst.setString(1,uname);
                    pst.setString(2,psw);
                    pst.setString(3,nam);
                    pst.setString(4,cit);
                    pst.setString(5,ema);
                    pst.setString(6,num);
                    pst.executeUpdate();
                    out.print("Successs");

        }catch(Exception e){
            out.print(e);
        }
    }
}
java mysql sql database servlets
1个回答
1
投票

将您的SQL语句更改为:

insert into login(uname,pass,name,city,email,phone) values(?,?,?,?,?,?)
© www.soinside.com 2019 - 2024. All rights reserved.