Fazer alteração na linha da jtable e salvar apos clicar no botão

0 respostas
java
L

Estou tentando salvar como explicado no cabeçalho e nao estou conseguindo.

int p = JOptionPane.showConfirmDialog(null, "Você deseja realmente salvar?", "Salvar", JOptionPane.YES_NO_OPTION);
    if (p == 0) {

        try {
            Class.forName(Auxiliar.AcessoBanco.getDriver());
            Connection con = DriverManager.getConnection(Auxiliar.AcessoBanco.getUrl(), Auxiliar.AcessoBanco.getUser(), Auxiliar.AcessoBanco.getPass());
            for (int i = 0; i < jTable1.getRowCount(); i++) {

                String ID_OEM = new String();
                String OEM = new String();
                ;

                try {
                    ID_OEM = jTable1.getValueAt(i, 1).toString();
                } catch (Exception e) {
                    ID_OEM = "";
                }

                try {
                    OEM = jTable1.getValueAt(i, 2).toString();
                } catch (Exception e) {
                    OEM = "";
                }

                if ((ID_OEM != "" || OEM != "")) {

                    String sql = "update OEM set OEM=? where id_oem=?";
                    PreparedStatement pst = con.prepareStatement(sql);

// int id_oem = Integer.parseInt(jTable1.getValueAt(i, 1).toString());//1
// String oem = (jTable1.getValueAt(i, 2).toString());//2
String id_oem = ID_OEM;//32
String oem = OEM;//33
//
// pst.setInt(1, id_oem);//1
// pst.setString(2, oem);//2
//
pst.setString(1, id_oem);//32
pst.setString(2, oem);//33

pst.executeUpdate();

                }

            }
                JOptionPane.showMessageDialog(null, "Salvo com sucesso!");
//                PreencherTabela();

} catch (Exception e) {

JOptionPane.showMessageDialog(null, e);

}
}
Criado 6 de outubro de 2017
Respostas 0
Participantes 1