0

I'm trying to update values using JDBC on spark and I continue to get the same error .

I used the following query

 statement.addBatch(("INSERT INTO gasoil_summeries " + "VALUES ("
                        + "'" + row.getAs("id_vehicule2")+"'"
                         + "'" + row.getInt(0)+"'"
                        +"'" + row.getAs("litre2")+"'"
                        +"'" +row.getDouble(1)+"'"
                        + "'"+row.getAs("count2")+"'"
                        +"'" + row.getInt(2)+"'"
                        +"'" + row.getAs("is_sup2")+"'"
                        +"'"+row.getInt(3)+"'"
                        +"'" +row.getAs("last_upd2")+"'"
                        +"'"+row.getTimestamp(4)+"'"
                        +")  ON DUPLICATE KEY UPDATE _id_vehicule='" + row.getAs("id_vehicule2") + "';"));

the number of columns is the same, but I continue to get the error "java.sql.SQLException: Column count doesn't match value count at row 1"

Thnak you.

1
  • It seems that you need to join this dataframes. Can you provide your code? Commented Jul 1, 2020 at 8:53

1 Answer 1

0

I found the solution , maybe that can help someone .

 statement.addBatch(("INSERT INTO gasoil_summeries " + "VALUES ("
                        +"'" + row.getAs("id_vehicule2") + "'"+ ","
                         //"'" + row.getInt(0)+"'"+
                        +"'" + row.getAs("litre2")+ "'"+ ","
                       // +"'" +row.getDouble(1)+"'"+
                       + "'"+row.getAs("count2")+ "'"+ ","
                      //  "'" + row.getInt(2)+"'"+
                       +"'" + row.getAs("is_sup2")+ "'"+ ","
                     //   "'"+row.getInt(3)+"'"+
                       + "'" +row.getAs("last_upd2")+ "'"+
                      //  "'"+row.getTimestamp(4)+
                ")  ON DUPLICATE KEY UPDATE id_vehicule = '"+ row.getInt(0)+"',d_littre= '"+row.getDouble(1)+"',counter = '"+row.getInt(2)+"',is_suspect ='"+row.getInt(3)+"',last_update='"+row.getTimestamp(4)+ "' ; "));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.