0
Hello, I have the following problem in question:
I made an array list to list data in a combo box, but it only lists the data from the first table, in this case: "catdesc", which is the description of a car category, whether it is Sporty, etc. But in the same table, has a column called catvalordiaria, IE, is the daily value of this car category.
In the combobox appears only the description:
I want to show, next to this description, the daily amount, ex: Sports - R $ 39,90; I don’t know if the problem is because the figure is double, or sla, I need your help. Here is my code from "Categoriadao" and just below Servicos.java, where you list the categories in the Combo Box.
package model.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import model.bean.Categoria;
import model.connection.ConnectionFactory;
public class CategoriaDao {
    Connection con=null;
    String sql;
    ResultSet rs;
    PreparedStatement pstm;
    ArrayList<Categoria> listacat=new ArrayList<>();
    public List<Categoria> listarCategorias(){
        try{           
         con=ConnectionFactory.getConnection();         
         sql= "SELECT catcodigo,catdesc,catvalordiaria FROM categoria ORDER BY catdesc";    
         pstm=con.prepareStatement(sql);            
         rs=pstm.executeQuery(sql);
         while(rs.next()){
         Categoria cat = new Categoria();
         cat.setCatCodigo(rs.getInt(1));
         cat.setCatDescricao(rs.getString(2));
         cat.setCatValorDiaria(rs.getDouble(3));
         listacat.add(cat);
         }
        }catch(Exception erro){
            JOptionPane.showMessageDialog(null,"Erro PSTM "+erro.getMessage());
        }
        return listacat;
            }
}
    public void preencherComboCategoria(JComboBox comboCategoria){
        CategoriaDao cat = new CategoriaDao();
        List<Categoria> listagem2 = cat.listarCategorias();
        for(Categoria c:listagem2){
            comboCategoria.addItem(c);
    }
}
}
