[code]public void insereTabela() {
String txt1 = txtData.getText(), txt2 = txtNum.getText(), txt3 = (String)cboHora.getSelectedItem();
int numTabela = tabela.getRowCount();
if (numTabela == 1 && resposta == false) {
tabela.removeRow(0);
tabela.addRow(new String[] {txt1,txt2,txt3});
resposta = true;
} else if (numTabela >= 5 && resposta == true) {
if ((String)cboHora.getSelectedItem() == “14:00”) {
insereBanco();
int n = JOptionPane.showConfirmDialog(this, “Este foi o primeiro sorteio do dia?\nDeseja cadastrar o sorteio das 18:00!?”,"", JOptionPane.YES_NO_OPTION);
if (n == JOptionPane.YES_OPTION) {
cboHora.setSelectedIndex(1);
txtNum.requestFocus();
limpaTable();
}
}
} else {
tabela.addRow(new String[] {txt1,txt2,txt3});
}
}
public void insereBanco() {
String valorHora = (String)cboHora.getSelectedItem();
String txt = txtData.getText();
String row1, row2, row3;
int cod;
if (valorHora == “14:00”) {
try {
stm = conn.createStatement();
rs = stm.executeQuery(“SELECT * FROM horario1”);
rs.last();
String codigo = rs.getString(“cod”);
cod = Integer.parseInt(codigo);
if (cod == 0) {
cod = 1;
} else {
cod++;
}
for (int i = 0; i < 5; i++) {
row1 = (String)tabela.getValueAt(i,0);
row2 = (String)tabela.getValueAt(i,1);
row3 = (String)tabela.getValueAt(i,2);
int rs2 = stm.executeUpdate("INSERT INTO horario1 VALUES(" + cod + ", '" + row1 + "','" + row2 + "','" + row3 + "')");
}
} catch (SQLException e) {
JOptionPane.showMessageDialog(this, "Não foi possível cadastrar esses sorteios!!!");
}
} else {
try {
stm = conn.createStatement();
rs = stm.executeQuery(“SELECT * FROM horario2”);
rs.last();
String codigo = rs.getString(“cod”);
cod = Integer.parseInt(codigo);
if (cod == 0) {
cod = 1;
} else {
cod++;
}
for (int i = 0; i < 5; i++) {
row1 = (String)tabela.getValueAt(i,0);
row2 = (String)tabela.getValueAt(i,1);
row3 = (String)tabela.getValueAt(i,2);
int rs2 = stm.executeUpdate("INSERT INTO horario2 VALUES(" + cod + ", '" + row1 + "','" + row2 + "','" + row3 + "')");
}
} catch (SQLException e) {
JOptionPane.showMessageDialog(this, "Não foi possível cadastrar esses sorteios!!!");
}
}
}[/code]