Hi all,

im doing a program using java and sql, and im trying to set a textbox with a value stored in a database.
thing is: i have a combo with airlines, and each airline has a cost for each seat. so what im trying to do is get this cost per seat and then multiply it per people traveling.

what i did is:

int cantidadgente;
        float valortotalvuelos;
        float valordelaclase;

        Statement sql;
        ResultSet rs;
        boolean seguir;
        Aerolineas_clase aerolinea;
        
        
        cantidadgente=Integer.parseInt(txtCantidadPersonas.getText());
        
        if (validarseleccioncomboaerolinea())
        {   
//            valortotalvuelos=;
            
            cmbAerolinea.getSelectedItem().toString();
  
 
            try
            {
                sql = conexiones.cnn.createStatement();
                aerolinea = new Aerolineas_clase();
                
                rs = sql.executeQuery("SELECT id_aerolinea,nombre_aerolinea,clase_aerolinea,costo FROM aerolineas WHERE nombre_aerolinea =" + cmbAerolinea.getSelectedItem().toString()); //here i compare to the string i have selected in the combo
                rs.next();     
                
                //with --> aerolinea.setPrecio(rs.getFloat(4)) --> i get the value for the seat
                valordelaclase = Float.parseFloat(aerolinea.setPrecio(rs.getFloat(4))); // 'void' type not allowed here
            }
            catch (Exception e)
                {JOptionPane.showMessageDialog (null,e.getMessage()+"error getAerolinea");}
            
            txtTotalAerolinea.setText(null);         
        }

idk how to set the value from the airline into a value i can use. have tried doing:

valortotalvuelos = (aerolinea.setPrecio(rs.getFloat(4))) * candidadgente; // 'void' type not allowed here

but still gives me that error.


thanks in advance!

Well I cant understand a thing.. sorry... English.

If you could post your entire code it would be helpful. with variables translated.

But someone here may be able to help you... your choice..

Here is the code for that part in English. The whole code will be worse its more than 1000 lines

int totalofpeople;
    float flightvalue;
    float classvalue;
     
    Statement sql;
    ResultSet rs;
    boolean seguir;
    Airlines_class airline;
     
     
    totalofpeople=Integer.parseInt(txtCantidadPersonas.getText());
     
    if (validarseleccioncomboaerolinea()) //this validates that the combo has something selected
    {
    // valortotalvuelos=;
     
    cmbAerolinea.getSelectedItem().toString();
     
     
    try
    {
    sql = conexiones.cnn.createStatement();
    airline = new Airlines_class();
     
    rs = sql.executeQuery("SELECT id_airline,name_airline,class_airline,cost FROM airlines WHERE name_airline =" + cmbAerolinea.getSelectedItem().toString()); //here i compare to the string i have selected in the combo
    rs.next();
     
    //with --> airline.setPrice(rs.getFloat(4)) --> i get the value for the seat
    classvalue = Float.parseFloat(aerolinea.setPrice(rs.getFloat(4))); // 'void' type not allowed here
    }
    catch (Exception e)
    {JOptionPane.showMessageDialog (null,e.getMessage()+"error getAerolinea");}
     
    txtTotalAerolinea.setText(classvalue);
    }

Thanks!

I think this might help. worth a try...

what is this line doing??

classvalue = Float.parseFloat(aerolinea.setPrice(rs.getFloat(4)));

parseFloat() expects a string. BUT DOES aerolinea.setPrice() return a STRING ???

Check that. If u want to set price and also extract the float value do it separately.

something like:

classvalue = Float.parseFloat(rs.getFloat(4));
aerolinea.setPrice(classvalue);

try this....

This article has been dead for over six months. Start a new discussion instead.