javasqljdbcjtable

SQL, trying to compare 2 int and getting error "Can't compare char and int"


I'm getting this error:

"java.sql.SQLSyntaxErrorException: No están soportadas las comparaciones entre 'INTEGER' y 'CHAR (UCS_BASIC)'. Los tipos deben ser comparables. Además, los tipos de cadena también deben tener una intercalación coincidente. Si la intercalación no coincide, una posible solución es convertir los operandos para forzarlos a la intercalación por defecto (por ejemplo: SELECT tablename FROM sys.systables WHERE CAST(tablename AS VARCHAR(128)) = 'T1')"

My database table has 11 positions, everything is a varchar but the first one, that's a int.

And I'm getting data from the jtable, everything but the col 0, which is a int, rest is strings.

And here is my code:

int colActual = jTableNombre.getSelectedRow();

private void jButtonGuardarNombreActionPerformed(java.awt.event.ActionEvent evt) {                                                     
    
    String nombre = (String) jTableNombre.getModel().getValueAt(colActual,1);
    String director=(String) jTableNombre.getModel().getValueAt(colActual,2);
    String año = (String) jTableNombre.getModel().getValueAt(colActual,3);
    String generos = (String) jTableNombre.getModel().getValueAt(colActual,4);
    String actores = (String) jTableNombre.getModel().getValueAt(colActual,5);
    String pais = (String) jTableNombre.getModel().getValueAt(colActual,6);
    String idioma = (String) jTableNombre.getModel().getValueAt(colActual,7);
    String doblaje = (String) jTableNombre.getModel().getValueAt(colActual,8);
    String subtitulos = (String) jTableNombre.getModel().getValueAt(colActual,9);
    String ubicacion = (String) jTableNombre.getModel().getValueAt(colActual,10);
    try {   
        Class.forName("com.mysql.jdbc.Driver");
        conn = DriverManager.getConnection(DB_URL, USER, PASS);
        stmt = conn.createStatement();
        String sql= "UPDATE MOVIES " + 
            "SET NOMBRE = '"+nombre+"', "+
            "DIRECTOR = '"+director+"', "+
            "AÑO = '"+año+"', "+
            "GENEROS = '"+generos+"', "+
            "ACTORES = '"+actores+"', "+
            "PAIS = '"+pais+"', "+
            "IDIOMA = '"+idioma+"', "+
            "DOBLAJE = '"+doblaje+"', "+
            "SUBTITULOS = '"+subtitulos+"', "+
            "UBICACION = '"+ubicacion+"' "+
            "WHERE ID = '"+id+"'";
        stmt.executeUpdate(sql);                           
        int i= stmt.executeUpdate(sql);
        System.out.print(i);
        if (i>0) {
            JOptionPane.showMessageDialog(null, "Movie Updated");  
        }
        else {
            JOptionPane.showMessageDialog(null, "Movie didn't update");
        }

    } 
    catch(Exception e) {
        System.out.println(e);
    }
    
}   


 

Solution

  • You are missing the id in this snippet of code:

        "WHERE ID = '"+id+"'";
    

    Try to add it.