Well I have a class 'neighborhood'

have it

private municipality >> ​​City which is the class municipio

and thus

I have a class cadastrobairroview

with the codes


private void initcombobox() {

try {
try {
Class.forName("com.mysql.jdbc.Driver");

} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}

Connection connection = (Connection) DriverManager.getConnection(
"jdbc:mysql://localhost:3306/cliente-db", "impacta",
"impacta");
Statement query = (Statement) connection.createStatement();

String sql = "SELECT * FROM municipio ";

ResultSet rs = query.executeQuery(sql);

List<Municipio> lisMunicipios = new ArrayList<Municipio>();

while (rs.next()) {
Municipio municipio = new Municipio();

municipio.setNome(rs.getString("id_uf"));
ufJComboBox.addItem(rs.getString("id_uf"));
municipio.setId(rs.getInt("id_municipio"));
municipioJComboBox.addItem(rs.getObject("nm_municipio"));

lisMunicipios.add(municipio);

}

} catch (SQLException cause) {
cause.printStackTrace();
JOptionPane.showMessageDialog(null, "Não foi possivel Carregar");

}

}















and I have Okbairroaction class


containing the codes


@Override
public void actionPerformed(ActionEvent e) {
String NomeBairro = view.getNomeJTextField().getText();
Object selecionar = (Object) view.getMunicipioJComboBox().getSelectedIndex();

Bairro domain;


try {
if (view.getaAlterar() != null) {
domain = (Bairro) view.getaAlterar();

} else {
domain = new Bairro();
}

domain.setNome(NomeBairro);
domain.setMunicipio((Municipio) selecionar);




view.getService().validar(domain);
view.getService().salvar(domain);

} catch (Exception cause) {
cause.printStackTrace();
JOptionPane.showMessageDialog(view, "erro ao carregar");
}

}




WHAT I want is to save the object in the combobox
save it in mysql int field the id of the referenced municipality
how to do?