Olá, Pessoal! Estou precisando resolver a situação a seguir, agradeço desde já
Embora já tenha dados cadastrados para Permissão, quando eu insiro o tipo de acesso grava novamente em Permissão, ou seja, está salvando em acesso e salva de novo em permissão, estou sem entender o motivo
public class ModPermissao {
protected int id_perm;
protected String permi;
public int getId_perm() {
return id_perm;}
public void setId_perm(int id_perm) {
this.id_perm = id_perm;}
public String getPermi() {
return permi; }
public void setPermi(String permi) {
this.permi = permi;}
}
public class ControlPermi {
ConectBD conectperm = new ConectBD();
public void Inserirperm (ModPermissao modperm){
conectperm.conecta();
try{
PreparedStatement pst = conectperm.conn.prepareStatement(“insert into permissao (permi)values(?)”);
pst.setString(1,modperm.getPermi());
pst.execute();
JOptionPane.showMessageDialog(null, “Dados de Tipo de Permissao: “+modperm.getPermi()+”+ armazenados com sucesso!”);
}catch(SQLException ex){
JOptionPane.showMessageDialog(null, “Erro ao cadastrar Tipo de permissao:” + ex);
}
conectperm.desconecta();
}
public void Excluirperm (ModPermissao modperm){
conectperm.conecta();
try{
PreparedStatement pst = conectperm.conn.prepareStatement("delete from permissao where id_perm=?");
pst.setInt(1,modperm.getId_perm());
pst.execute();
JOptionPane.showMessageDialog(null, "Dados Tipo de permissao"+modperm.getPermi()+" deletados com sucesso!");
}catch(SQLException ex){
JOptionPane.showMessageDialog(null, "Erro ao deletar Tipo de permissao:" + ex);
}
conectperm.desconecta();
}
public void Alterarperm (ModPermissao modperm){
conectperm.conecta();
try{
PreparedStatement pst = conectperm.conn.prepareStatement("update permissao set permi=? where id_perm=?");
pst.setString(1,modperm.getPermi());
pst.execute();
JOptionPane.showMessageDialog(null, "Dados Tipo de permissao: "+modperm.getPermi()+" alterados com sucesso!");
}catch(SQLException ex){
JOptionPane.showMessageDialog(null, "Erro ao atualizar Tipo de permissao:" + ex);
}
conectperm.desconecta();
}
}
public class GerPerm extends javax.swing.JFrame {
ConectBD conPerm = new ConectBD();
ControlPermi clp = new ControlPermi();
ModPermissao modperm = new ModPermissao();
public GerPerm() {
initComponents();
conPerm.conecta();
//preencherTabela("select * from permissao order by id_perm");
}
public void preencherTabela(String SQL){
ArrayList dados = new ArrayList();
String[] Colunas = new String[]{"Cod", "Permissao"};
conPerm.executaSQL(SQL);
try{
conPerm.rs.first();
do{
dados.add(new Object[]{conPerm.rs.getInt("id_perm"),conPerm.rs.getString("permi")});
}while(conPerm.rs.next());
conPerm.desconecta();
} catch (SQLException ex) {
JOptionPane.showMessageDialog(rootPane, "Erro ao preencher a ArrayList!\n Erro:" + ex);
conPerm.desconecta();
}
ModeloTabela modtab = new ModeloTabela(dados, Colunas);
jTCad.setModel(modtab);
jTCad.getColumnModel().getColumn(0).setPreferredWidth(80);
jTCad.getColumnModel().getColumn(0).setResizable(false);
jTCad.getColumnModel().getColumn(1).setPreferredWidth(450);
jTCad.getColumnModel().getColumn(1).setResizable(false);
jTCad.getColumnModel().getColumn(2).setPreferredWidth(80);
jTCad.getColumnModel().getColumn(2).setResizable(false);
jTCad.getTableHeader().setReorderingAllowed(false);
jTCad.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
jTCad.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
//jTCadSec.setSelectionModel(ListSelectionModel.SINGLE_SELECTION);
}
public void salvar () {
modperm.setPermi(jTFPermi.getText());
clp.Inserirperm(modperm);
//preencherTabela("select * from permissao order by id_permi");
jTFCodPerm.setText("");
jTFPermi.setText("");
jTFPermi.setEnabled(true);
jBAtu.setEnabled(false);
jBDel.setEnabled(false);
jBSalvar.setEnabled(false);
jBNew.setEnabled(true);
}
public void deletar () {
modperm.setId_perm(Integer.parseInt(jTFCodPerm.getText()));
modperm.setPermi(jTFPermi.getText());
clp.Excluirperm(modperm);
//preencherTabela("select * from permissao order by id_permi");
jTFCodPerm.setText("");
jTFPermi.setText("");
jTFPermi.setEnabled(false);
jBAtu.setEnabled(false);
jBDel.setEnabled(false);
jBSalvar.setEnabled(false);
jBNew.setEnabled(true);
}
public void atualizar () {
modperm.setId_perm(Integer.parseInt(jTFCodPerm.getText()));
modperm.setPermi(jTFPermi.getText());
clp.Alterarperm(modperm);
//preencherTabela("select * from permissao order by id_permi");
jTFCodPerm.setText("");
jTFPermi.setText("");
jTFPermi.setEnabled(false);
jBAtu.setEnabled(false);
jBDel.setEnabled(false);
jBSalvar.setEnabled(false);
jBNew.setEnabled(true);
}
private void initComponents() {
jLTitulo = new javax.swing.JLabel();
jTFCodPerm = new javax.swing.JTextField();
jLCod = new javax.swing.JLabel();
jLPermi = new javax.swing.JLabel();
jTFPermi = new javax.swing.JTextField();
jBSair = new javax.swing.JButton();
jBUlt = new javax.swing.JButton();
jBProx = new javax.swing.JButton();
jBAnt = new javax.swing.JButton();
jBPri = new javax.swing.JButton();
jBDel = new javax.swing.JButton();
jBAtu = new javax.swing.JButton();
jBSalvar = new javax.swing.JButton();
jBNew = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTCad = new javax.swing.JTable();
jLBG = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("GESTÃO DE PERMISSÕES");
getContentPane().setLayout(null);
jLTitulo.setFont(new java.awt.Font("Segoe UI", 1, 36)); // NOI18N
jLTitulo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLTitulo.setText("GESTÃO DE PERMISSÕES");
getContentPane().add(jLTitulo);
jLTitulo.setBounds(0, 20, 680, 40);
jTFCodPerm.setEditable(false);
jTFCodPerm.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTFCodPermActionPerformed(evt);
}
});
getContentPane().add(jTFCodPerm);
jTFCodPerm.setBounds(90, 100, 60, 30);
jLCod.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLCod.setText("Código:");
getContentPane().add(jLCod);
jLCod.setBounds(30, 110, 60, 17);
jLPermi.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLPermi.setText("Tipo de Permissao: ");
getContentPane().add(jLPermi);
jLPermi.setBounds(160, 110, 140, 17);
getContentPane().add(jTFPermi);
jTFPermi.setBounds(300, 100, 360, 30);
jBSair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMGS/sair40x40.png"))); // NOI18N
jBSair.setToolTipText("Sair");
jBSair.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBSairActionPerformed(evt);
}
});
getContentPane().add(jBSair);
jBSair.setBounds(530, 150, 40, 50);
jBUlt.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMGS/ultimo40x40.png"))); // NOI18N
jBUlt.setToolTipText("Último");
jBUlt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBUltActionPerformed(evt);
}
});
getContentPane().add(jBUlt);
jBUlt.setBounds(480, 150, 40, 50);
jBProx.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMGS/proximo40x40.png"))); // NOI18N
jBProx.setToolTipText("Próximo");
jBProx.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBProxActionPerformed(evt);
}
});
getContentPane().add(jBProx);
jBProx.setBounds(430, 150, 40, 50);
jBAnt.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMGS/anterior40x40.png"))); // NOI18N
jBAnt.setToolTipText("Anterior");
jBAnt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBAntActionPerformed(evt);
}
});
getContentPane().add(jBAnt);
jBAnt.setBounds(380, 150, 40, 50);
jBPri.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMGS/primeiro40x40.png"))); // NOI18N
jBPri.setToolTipText("Primeiro");
jBPri.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBPriActionPerformed(evt);
}
});
getContentPane().add(jBPri);
jBPri.setBounds(330, 150, 40, 50);
jBDel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMGS/deletar40x40.png"))); // NOI18N
jBDel.setToolTipText("Excluir");
jBDel.setEnabled(false);
jBDel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBDelActionPerformed(evt);
}
});
getContentPane().add(jBDel);
jBDel.setBounds(280, 150, 40, 50);
jBAtu.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMGS/atualizar40x40.png"))); // NOI18N
jBAtu.setToolTipText("Atualizar");
jBAtu.setEnabled(false);
jBAtu.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBAtuActionPerformed(evt);
}
});
getContentPane().add(jBAtu);
jBAtu.setBounds(230, 150, 40, 50);
jBSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMGS/salvar40x40.png"))); // NOI18N
jBSalvar.setToolTipText("Salvar");
jBSalvar.setEnabled(false);
jBSalvar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBSalvarActionPerformed(evt);
}
});
getContentPane().add(jBSalvar);
jBSalvar.setBounds(180, 150, 40, 50);
jBNew.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMGS/novo40x40.png"))); // NOI18N
jBNew.setToolTipText("Novo");
jBNew.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBNewActionPerformed(evt);
}
});
getContentPane().add(jBNew);
jBNew.setBounds(130, 150, 40, 50);
jTCad.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{},
{},
{},
{}
},
new String [] {
}
));
jScrollPane1.setViewportView(jTCad);
getContentPane().add(jScrollPane1);
jScrollPane1.setBounds(30, 220, 630, 230);
jLBG.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMGS/BackgroundESQ.png"))); // NOI18N
jLBG.setRequestFocusEnabled(false);
getContentPane().add(jLBG);
jLBG.setBounds(0, -60, 790, 680);
setSize(new java.awt.Dimension(707, 511));
setLocationRelativeTo(null);
}// </editor-fold>
private void jTFCodPermActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jBSairActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
}
private void jBUltActionPerformed(java.awt.event.ActionEvent evt) {
ult();
}
private void jBProxActionPerformed(java.awt.event.ActionEvent evt) {
prox();
}
private void jBAntActionPerformed(java.awt.event.ActionEvent evt) {
ant();
}
private void jBPriActionPerformed(java.awt.event.ActionEvent evt) {
prim();
}
private void jBDelActionPerformed(java.awt.event.ActionEvent evt) {
deletar();
}
private void jBAtuActionPerformed(java.awt.event.ActionEvent evt) {
atualizar();
}
private void jBSalvarActionPerformed(java.awt.event.ActionEvent evt) {
salvar();
}
private void jBNewActionPerformed(java.awt.event.ActionEvent evt) {
jTFCodPerm.setText("");
jTFPermi.setText("");
jBAtu.setEnabled(true);
jBDel.setEnabled(true);
jBSalvar.setEnabled(true);
jBNew.setEnabled(false);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(GerPerm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(GerPerm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(GerPerm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(GerPerm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new GerPerm().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jBAnt;
private javax.swing.JButton jBAtu;
private javax.swing.JButton jBDel;
private javax.swing.JButton jBNew;
private javax.swing.JButton jBPri;
private javax.swing.JButton jBProx;
private javax.swing.JButton jBSair;
private javax.swing.JButton jBSalvar;
private javax.swing.JButton jBUlt;
private javax.swing.JLabel jLBG;
private javax.swing.JLabel jLCod;
private javax.swing.JLabel jLPermi;
private javax.swing.JLabel jLTitulo;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTCad;
private javax.swing.JTextField jTFCodPerm;
private javax.swing.JTextField jTFPermi;
// End of variables declaration
}
CREATE TABLE IF NOT EXISTS public.permissao
(
permi character varying COLLATE pg_catalog.“default”,
id_perm integer NOT NULL DEFAULT nextval(‘permissao_id_perm_seq’::regclass),
CONSTRAINT pk_perm PRIMARY KEY (id_perm)
)