With my little knowledge I give you my opinion according to what I understood of your code you have a "cost" table in which you select all the fields or columns within them if you show the type of service and you want to work with the value of each one you should first get the service type example: TYPE_SERVICE: GAS COST: 00.00 you must select the gas service to do a search with the name of the service and get the value of it in a variable and with it you would work.
To show the type of service:
modelo.addElement(rs.getString(tipoServicio));
TO BE MORE SPECIFIC HERE AN EXAMPLE
package nodelado;
import javax.swing. ;
import java.awt. ;
import java.sql. ;
import java.awt.event. ;
public class Nodelado {
public static void main(String[] args) {
combo c = new combo();
}
}
class combo extends JFrame implements ActionListener {
Statement stm;
ResultSet rst;
JComboBox combo = new JComboBox();
JButton boton = new JButton("PRECIONAME");
JTextField texto = new JTextField("0");
public combo() {
try {
Connection conexion = DriverManager.getConnection("jdbc:ucanaccess://d:/modelado.accdb");
stm = conexion.createStatement();
rst = stm.executeQuery("SELECT * FROM tipoServicio");
while (rst.next()) {
combo.addItem(rst.getString("tipoServicio"));
}
System.out.println("CONEXION REALIZADA CON EXITO");
} catch (SQLException sql) {
System.out.println("ERROR AL CONECTARSE A LA BASE DE DATOS" + sql);
}
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
setVisible(true);
setSize(300, 300);
texto.setBounds(150,100,100,20);
boton.setBounds(25, 150, 150, 20);
combo.setBounds(25, 100, 100, 20);
boton.addActionListener(this);
add(texto);
add(boton);
add(combo);
}
@Override
public void actionPerformed(ActionEvent e) {
Double valor = Double.parseDouble(texto.getText());
String seleccion = combo.getSelectedItem().toString();
try {
rst = stm.executeQuery("SELECT * FROM tipoServicio WHERE (TipoServicio='" + seleccion + "')");
while (rst.next()) {
System.out.println(rst.getDouble("costo"));
System.out.println("EL TOTAL ES " +(valor * rst.getDouble("costo")) );
}
} catch (SQLException sql) {
System.out.println(sql);
}
}
}
I did it using a database in access but that is the logic that I understood.
In my case I only have two records
I WAIT FOR YOU HELP.