Skip to main content

PROBLEM INSERT INTO JAVA WITH MYSQL (SWING)

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
No replies
Markiron
Offline
Joined: 2013-11-22

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 lisMunicipios = new ArrayList();

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