[mysql]列数不匹配行的值计数。如何匹配的值

标签: sql MySQL Java
发布时间: 2015/6/12 0:03:31
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我的工作与将数据插入到 mysql 数据库使用的 jsp 为什么不进入 database.the 错误显示出"列数不匹配值计数在行 1" 谁能解决我的问题,说我去哪里错了请帮我的朋友

 java code
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class Dealer extends HttpServlet {
private static final long serialVersionUID = 1L;


protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException

{
int a1=0;
response.setContentType("text/html");
PrintWriter out= response.getWriter();


    String dealId=request.getParameter("dealer_id");
    System.out.println(dealId);

    String dealName=request.getParameter("dealer_name");
    System.out.println(dealName);

    String doorNo=request.getParameter("door_no");
    System.out.println(doorNo);

    String street=request.getParameter("street");
    System.out.println(street);

    String city=request.getParameter("city");
    System.out.println(city);

    String district=request.getParameter("district");
    System.out.println(district);

    String state=request.getParameter("state");
    System.out.println(state);

    String pinCode=request.getParameter("pin_code");
    System.out.println(pinCode);

    String mob=request.getParameter("mobile");
    System.out.println(mob);

    String contactPerson=request.getParameter("contact_person");
    System.out.println(contactPerson);

    String phoneNo=request.getParameter("phone_no");
    System.out.println(phoneNo);

    String emailId=request.getParameter("email_id");
    System.out.println(emailId);

    String fax=request.getParameter("fax");
    System.out.println(fax);

    String crdOffI=request.getParameter("credit_offered_i");
    System.out.println(crdOffI);

    String crdOff=request.getParameter("credit_offered");
    System.out.println(crdOff);

    String vendorRating=request.getParameter("vendor_rating");
    System.out.println(vendorRating);

    String gstNo=request.getParameter("gst_no");
    System.out.println(gstNo);

    String cstNo=request.getParameter("cst_no");
    System.out.println(cstNo);

    String remarks=request.getParameter("remarks");
    System.out.println(remarks);


    String saveOrUpdate = request.getParameter("hiddenValue");
    System.out.println(saveOrUpdate);



try

{
Class.forName("com.mysql.jdbc.Driver");

System.out.println("driver loaded");
System.out.println("Driver is loaded");
Connection con= (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/charms?user=root&password=root");
System.out.println("Connection created");
PreparedStatement ps =null;
    if(saveOrUpdate.equals("update"))
    {
        ps= ((java.sql.Connection) con).prepareStatement("update dealer_masters set deal_name_v =?, deal_door_no_v =?, deal_street_v =?, deal_city_v =?, deal_district_v=?, deal_state_v=?, deal_contactperson_v=?, deal_phone_no_v=?, deal_mobile_no_v=?, deal_faxno_v=?, deal_email_id_v=?, deal_creditoffered_i=?, deal_period_v=?, deal_vendor_rating_v=?, deal_CST_No_v=?, deal_GST_No_V=?,Remarks_v =? where deal_id_v=? ");

        ps.setString(1,dealName);
        ps.setString(2,doorNo);
        ps.setString(3,street);
        ps.setString(4,city);
        ps.setString(5,district);
        ps.setString(6,state);
        ps.setString(7,pinCode);
        ps.setString(8,contactPerson);
        ps.setString(9,phoneNo);
        ps.setString(10,mob);
        ps.setString(11,fax); 
        ps.setString(12,emailId);
        ps.setString(13,crdOffI);
        ps.setString(14,crdOff);
        ps.setString(15,vendorRating);
        ps.setString(16,cstNo);
        ps.setString(17,gstNo);
        ps.setString(18,remarks);
        ps.setString(19,dealId);


        a1=ps.executeUpdate();
        if(a1==1)
        {
            System.out.println("Inserted");
            request.getSession().setAttribute("status1", "updatesuccess");
        }

    }
    else
    {   

         ps= ((java.sql.Connection) con).prepareStatement("insert into dealer_masters(deal_id_v,deal_name_v, deal_door_no_v, deal_street_v, deal_city_v, deal_district, deal_state_v, deal_contactperson_v, deal_phone_no_v, deal_mobile_no_v, deal_faxno_v, deal_email_id_v, deal_creditoffered_i, deal_period_v, deal_vendor_rating_v, deal_CST_No_v, deal_GST_No_V,Remarks_v) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
            ps.setString(1,dealId);
            ps.setString(2,dealName);
            ps.setString(3,doorNo);
            ps.setString(4,street);
            ps.setString(5,city);
            ps.setString(6,district);
            ps.setString(7,state);
            ps.setString(8,pinCode);
            ps.setString(9,contactPerson);
            ps.setString(10,phoneNo);
            ps.setString(11,mob);
            ps.setString(12,fax); 
            ps.setString(13,emailId);
            ps.setString(14,crdOffI);
            ps.setString(15,crdOff);
            ps.setString(16,vendorRating);
            ps.setString(17,cstNo);
            ps.setString(18,gstNo);
            ps.setString(19,remarks);


        a1=ps.executeUpdate();
        System.out.println("Inserted");
        request.getSession().setAttribute("status1", "success");
    }

}
catch(Exception e1)

{

System.out.println(e1.getMessage());
request.getSession().setAttribute("status1", "fail");
}

    response.sendRedirect("dealer.jsp");

}
}

解决方法 1:

在此声明:

insert into dealer_masters(
deal_id_v,
deal_name_v, 
deal_door_no_v, 
deal_street_v, 
deal_city_v, 
deal_district, 
deal_state_v, 
deal_contactperson_v, 
deal_phone_no_v, 
deal_mobile_no_v, 
deal_faxno_v, 
deal_email_id_v, 
deal_creditoffered_i, 
deal_period_v, 
deal_vendor_rating_v, 
deal_CST_No_v, 
deal_GST_No_V,
Remarks_v) /* 18 columns */
values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) /* 19 parameters*/

列列表包含 18 列但值列表包含 19 参数。 我假设您添加额外的参数,或错过了一列。 SQL 语句必须改变,所以列和参数列表是等于大小。

赞助商