executeUpdate - incompatible types: int can not be converted to java.sql.ResultSet JAVA

1

I am trying using a JDialog of a high vehicle form to make an insert in a table in the database. Pressing the " Enviar/OK/Insertar " button to add it to the database gives me the following error:

Uncompilable source code - incompatible types: int cannot be converted to java.sql.ResultSet

I leave you the whole function so you can see how rs=stm.executeUpdate(insertar_vehiculo); is where the fault is.

public static void alta_vehiculo(Vehiculo v){
        String bd = Conexiones.bbdd;
        Connection c = (Connection) Conexiones.conexion_a_BBDD(bd);
        Statement stm;
        ResultSet rs;
        String insertar_vehiculo = "";
        try{
            //Consulta para insertar un nuevo vehículo en la base de datos.
            stm = c.createStatement();
            //Comprobamos si v es una instancia de Vehiculo_Alquiler...
            if(v instanceof Vehiculo_Alquiler){
                insertar_vehiculo = "INSERT INTO vehiculos "
                        + "(bastidor, color, matricula, marca, modelo, potencia, consumo, "
                        + "fecha_fabricacion, descripcion) "
                        + "VALUES "
                        + "('"+v.getBastidor()+"', '"+v.getColor()+"', '"+v.getMatricula()+"', "+v.getMarca()+","
                        + "'"+v.getModelo()+"', "+v.getPotencia()+", "+v.getConsumo()+", "
                        + "'"+v.getFecha_fabricacion()+"', '"+v.getDescripcion()+"');";
                rs = stm.executeUpdate(insertar_vehiculo);

                String insertar_vehiculo_alquiler = "INSERT INTO vehiculos_alquiler "
                        + "(bastidor, precio_alquiler, fecha_v_alquiler, disponible) "
                        + "VALUES "
                        + "('"+v.getBastidor()+"', "+((Vehiculo_Alquiler)v).getPrecio_alquiler()+", "
                        + "'"+((Vehiculo_Alquiler)v).getFecha_v_alquiler()+", "+((Vehiculo_Alquiler)v).isDisponible()+"');";
                rs = stm.executeUpdate(insertar_vehiculo_alquiler);
                System.out.println("Vehículo insertado correctamente en vehiculo y vehiculo_alquiler.");
            }else{
                //Al no ser una instancia de Vehiculo_Alquiler, lo será de Vehiculo_Compra.
                insertar_vehiculo = "INSERT INTO vehiculos "
                        + "(bastidor, color, matricula, marca, modelo, potencia, consumo, "
                        + "fecha_fabricacion, descripcion) "
                        + "VALUES "
                        + "('"+v.getBastidor()+"', '"+v.getColor()+"', '"+v.getMatricula()+"', "+v.getMarca()+","
                        + "'"+v.getModelo()+"', "+v.getPotencia()+", "+v.getConsumo()+", "
                        + "'"+v.getFecha_fabricacion()+"', '"+v.getDescripcion()+"');";
                rs = stm.executeUpdate(insertar_vehiculo);
                String insertar_vehiculo_compra = "INSERT INTO vehiculos_compra "
                        + "(bastidor, precio_venta, fecha_v_compra) "
                        + "VALUES "
                        + "('"+v.getBastidor()+"', "+((Vehiculo_Compra)v).getPrecio_venta()+"', "+((Vehiculo_Compra)v).getFecha_v_compra()+"');";
                rs = stm.executeUpdate(insertar_vehiculo_compra);
                System.out.println("Vehículo insertado correctamente en vehiculo y vehiculo_compra.");
            }
            c.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    
asked by omaza1990 28.12.2016 в 14:01
source

1 answer

1

executeUpdate does not return a ResultSet, it returns the number of rows affected by the executed query.

Here you have more info:

  

link

    
answered by 28.12.2016 / 14:14
source