Skip to content
Advertisement

I’m trying to update the values ​of a table SQL have an error in Java

I’m trying to update the values ​​of a table, but it throws an error that I have not been able to determine. If you visualize it it would help me, this is what it throws by console:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘name=’Proyecto ‘ status=0 language=’PHP’ duration=16 advance=16 effec=0.0 where ‘ at line 1

public int actualizar(Proyecto p, int pos) {
        String sql = "UPDATE proyecto SET code=? name=? status=? language=? duration=? advance=? effec=? where code='"+ pos +"' " ;
        try {
            con = conectar.getConexionSQL();
            ps=con.prepareStatement(sql);
            ps.setInt(1, p.getCod());
            ps.setString(2, p.getNombre());
            ps.setInt(3, p.getStatus());
            ps.setString(4, "PHP");
            ps.setInt(5, p.getDuracion());
            ps.setInt(6, p.getAvance());
            ps.setDouble(7, 0.0);
            ps.executeUpdate();

            return 1;   
        } catch(Exception e){
            e.printStackTrace();
        }
        return 1;
    }

Advertisement

Answer

Assignments in the SET must be separated by commas:

UPDATE proyecto 
SET code = ?, name = ?, status = ?, language = ?, duration = ?, advance = ?, effec=?
WHERE code = ?

Possibly unrelated note: do you really mean to update column code, which you are using to identify which record(s) should be updated? Although this is valid SQL, this might not really make sense from functional perspective.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement