I'm going through a cycle with values, and at each iteration I call a Jframe to choose certain values, what happens is that all Jframes are opened without being able to complete the operation before. In my code the "fetchEditor" calls the JFrame but does not wait until the operations are completed and the cycle continues. How do I?
try {
conX3 = connection.getConnection();
stmtX3 = conX3.createStatement();
itens = this.getItens();
for (int k = 0; k < itens.length; k++) {
String sql = "SELECT * FROM ALMEDINA.YITMNET WHERE ISBN_0 = '" + itens[k] + "'";
ResultSet rsX3 = stmtX3.executeQuery(sql);
while (rsX3.next()) {
fetchEditoras(rsX3.getString("EDITORA_0"));
}
}
} catch (SQLServerException ex) {
Logger.getLogger(SQLServerException.class.getName()).log(Level.WARNING, null, ex);
} finally {
conX3.close();
stmtX3.close();
}
public ArrayList<Editora> fetchEditoras(String editora) throws ClassNotFoundException, SQLException {
DatabaseNET connectionNet = new DatabaseNET();
ImportX3Net connectionX3Net = new ImportX3Net();
Connection conX3Net = null, conNet = null;
Statement stmtX3Net = null, stmtNet = null;
ArrayList<Editora> editoras = new ArrayList<>();
if (connectionX3Net.getConnection() != null) {
try {
conX3Net = connectionX3Net.getConnection();
conNet = connectionNet.getConnection();
stmtX3Net = conX3Net.createStatement();
stmtNet = conNet.createStatement();
String sql = "SELECT * FROM importXNet.editora WHERE x3_name LIKE '" + editora + "'";
ResultSet rsX3NETEditora = stmtX3Net.executeQuery(sql);
if (stmtX3Net.getFetchSize() == 0) {
sql = "SELECT * FROM loja_online.editoras WHERE editoras_name LIKE '%" + editora + "%'";
ResultSet rsNet = stmtNet.executeQuery(sql);
while (rsNet.next()) {
System.out.println(rsNet.getString("editoras_name"));
editoras.add(new Editora(null, rsNet.getString("editoras_name")));
}
assocEditoras assoc = new assocEditoras(editoras, editora);
assoc.setVisible(true);
rsNet.close();
}
} catch (MySQLDataException ex) {
Logger.getLogger(MySQLDataException.class.getName()).log(Level.SEVERE, null, ex);
} finally {
stmtNet.close();
stmtX3Net.close();
}
}
return editoras;
}