java.sql.SQLException:没有为参数3 java+;Mysql

java.sql.SQLException:没有为参数3 java+;Mysql,java,mysql,parameters,prepared-statement,batch-processing,Java,Mysql,Parameters,Prepared Statement,Batch Processing,我是巴西人,我正在尝试在数据库MySQL上进行批处理 但是错误 “java.sql.SQLException:没有为参数3指定值” 坚持 public ClienteCRUD(String nome, String cpf, String endereco, String cidade, String uf, String cep) throws SQLException { String[] str = {nome, cpf, endereco, cidade, uf, ce

我是巴西人,我正在尝试在数据库MySQL上进行批处理

但是错误

“java.sql.SQLException:没有为参数3指定值”

坚持

public ClienteCRUD(String nome, String cpf, String endereco, String cidade, String uf, String cep) throws SQLException {

        String[] str = {nome, cpf, endereco, cidade, uf, cep};

        String url = "jdbc:mysql://localhost/vendas";
        String sql = "insert into cliente (id_cliente, nomeCliente, enderecoCliente, cidade, cep, uf, cpf) values (?,?,?,?,?,?,?);";
        try (Connection con = DriverManager.getConnection(url, "root", "fabiio2");
        PreparedStatement stm = con.prepareStatement(sql)) {
            for (int i = 0; i < str.length; i++) {
                if (i == 0) {
                    stm.setInt(1, i + 4);
                    stm.setString(2, str[i]);
                }
                else {
                    stm.setString(i + 2, str[i]);
                }
                stm.addBatch();
            }
            stm.executeBatch();
    }

    }
public ClienteCRUD(字符串nome、字符串cpf、字符串endereco、字符串cidade、字符串uf、字符串cep)抛出SQLException{
字符串[]str={nome,cpf,endereco,cidade,uf,cep};
String url=“jdbc:mysql://localhost/vendas";
String sql=“插入到客户(id_客户、nomeclient、enderecoclient、cidade、cep、uf、cpf)值(?,,,,,,,,,;”;
try(Connection con=DriverManager.getConnection(url,“root”,“fabiio2”);
PreparedStatement stm=con.prepareStatement(sql)){
对于(int i=0;i
我的数据库包含七列,其中第一列是自动分配的

对不起,我是Java新手

我指望你的帮助。

public ClienteCRUD(字符串nome、字符串cpf、字符串endereco、字符串cidade、字符串uf、字符串cep)抛出SQLException{
    public ClienteCRUD(String nome, String cpf, String endereco, String cidade, String uf, String cep) throws SQLException {
            String[] str = {nome, cpf, endereco, cidade, uf, cep};
            String url = "jdbc:mysql://localhost/vendas";
            String sql = "insert into cliente (id_cliente, nomeCliente, enderecoCliente, cidade, cep, uf, cpf) values (?,?,?,?,?,?,?)";
            try (Connection con = DriverManager.getConnection(url, "root", "fabiio2");
            PreparedStatement stm = con.prepareStatement(sql)) {

            //for a sql complete parameter
            for (int i = 0; i < str.length; i++) {
                if (i == 0) {
                     stm.setInt(1, i + 4);
                     stm.setString(2, str[i]);
                }
                else {
                     stm.setString(i + 2, str[i]);
                }
            }
            // to move this 
            stm.addBatch();
            stm.executeBatch();            
          }
        }
字符串[]str={nome,cpf,endereco,cidade,uf,cep}; String url=“jdbc:mysql://localhost/vendas"; String sql=“插入到客户(id_客户、nomeclient、enderecoclient、cidade、cep、uf、cpf)值(?,,,,,,,,,?)”; try(Connection con=DriverManager.getConnection(url,“root”,“fabiio2”); PreparedStatement stm=con.prepareStatement(sql)){ //对于sql complete参数 对于(int i=0;i
谢谢!成功了!你能解释一下为什么“add.batch”在“for”之外吗?我认为在每个循环中“for”都有一个“batch”指令来组装整个过程。再次感谢你!