String sql;
sql = "SELECT * FROM MARCA ";
Conectar conectar = new Conectar(); // clase que ejecuta la sentencia en el motor
ResultSet rs = conectar.consultar(sql);
Vector modelo = new Vector();
int i=0;
try {
while(rs.next())
{
modelo.addElement(new Item(rs.getInt(1), rs.getString(2)));
}
} catch (SQLException ex) {
Logger.getLogger(frmProducto.class.getName()).log(Level.SEVERE, null, ex);
}
cmbMarca.setModel(new javax.swing.DefaultComboBoxModel(modelo));
// clase auxiliar que permitirá agregar elementos al combo
class Item
{
private int id;
private String description;
public Item(int id, String description)
{
this.id = id;
this.description = description;
}
public int getId()
{
return id;
}
public String getDescription()
{
return description;
}
public String toString()
{
return description;
}
}
|