Bom vou contar meu dilema;
Sou novo em programação me apaixonei pelo java assim que comecei a mexer com ele. Estou fazendo um programa simples. Mas já quero implementar algo assim:
1- todo CRUD feito no sistema desde o login de usuario quero gravar em uma tabela no mysql que
vai receber um id auto increment, nome da tabela acessada, tipo de modificação como, insert, update, delete, ect.
usuario que fez, descrição, ou seja, o que estava antes e pra que foi alterado, data, hora e host da maquina que foi usado.
Quero começar com minha tela de login, pegando informações do usuario, tabela ou seja usuario, tipo ou seja login, descrição logou no sistema, etc…
To batendo cabeça… quem puder me ajudar… não prometo muito mais uma pizza eu pago só pra comemorar, transfiro o valor da pizza e da coca cola ta fechado.
segue meu código de login:
/*
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
/
package view;
import java.sql.;
import conexao.Mysql;
import javax.swing.JOptionPane;
/**
*
-
@author Augusto Araujo
*/
public class Login extends javax.swing.JFrame {
//fremeowrks que estão dentro do pacote de conexão
Connection conexao = null;
PreparedStatement pst = null;
ResultSet rs = null;//criar os metodos
public void logar(){
//query que vai ser executar a consulta ao banco
String sql = “select * from usuarios where cpf=? and senha=?”;
try{
pst = conexao.prepareStatement(sql);
pst.setString(1, txtCpf.getText());
pst.setString(2, txtSenha.getText());
rs = pst.executeQuery();if (rs.next()){ String situacao = rs.getString(6); if (situacao.equals("ativo")){ //logs String sql2 = "INSERT INTO _comercio.logs (tabela) VALUES (?)"; try{ this.pst.setString(1,txtCpf.getText()); this.rs = pst.executeQuery(sql2); }catch(Exception e){ } //final logs TelaPrincipal principal = new TelaPrincipal(); principal.setVisible(true); this.dispose(); conexao.close(); }else{ JOptionPane.showMessageDialog(null, "Usuário inativo"); this.dispose(); conexao.close(); } } else { JOptionPane.showMessageDialog(null, "Login ou senha inválido"); }
} catch (Exception e){
}
}
/**
- Creates new form Login
*/
public Login() {
initComponents();
conexao = Mysql.conector();
if (conexao != null) {
lblStatus.setText(“Conectado ao banco”);
}else {
lblStatus.setText(“Desconectado”);
}
}
/**
-
This method is called from within the constructor to initialize the form.
-
WARNING: Do NOT modify this code. The content of this method is always
-
regenerated by the Form Editor.
*/
@SuppressWarnings(“unchecked”)
//
private void initComponents() {txtCpf = new javax.swing.JTextField();
txtSenha = new javax.swing.JPasswordField();
btnEntrar = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
lblStatus = new javax.swing.JLabel();
lblFundo = new javax.swing.JLabel();setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle(“Login”);
setResizable(false);
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
getContentPane().add(txtCpf, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 90, 150, 30));txtSenha.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtSenhaActionPerformed(evt);
}
});
getContentPane().add(txtSenha, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 130, 150, 30));btnEntrar.setText(“ENTRAR”);
btnEntrar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnEntrarActionPerformed(evt);
}
});
getContentPane().add(btnEntrar, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 180, -1, -1));jLabel1.setFont(new java.awt.Font(“Tahoma”, 1, 16)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel1.setText(“CPF”);
getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 100, -1, -1));jLabel2.setFont(new java.awt.Font(“Tahoma”, 1, 16)); // NOI18N
jLabel2.setForeground(new java.awt.Color(255, 255, 255));
jLabel2.setText(“Senha”);
getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 140, -1, -1));lblStatus.setForeground(new java.awt.Color(255, 255, 255));
lblStatus.setText(“conexão com banco de dados”);
getContentPane().add(lblStatus, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 250, -1, -1));
lblStatus.getAccessibleContext().setAccessibleName("");lblFundo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/fundo_login.png"))); // NOI18N
getContentPane().add(lblFundo, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));pack();
setLocationRelativeTo(null);
}//
private void txtSenhaActionPerformed(java.awt.event.ActionEvent evt) {
// chamando o metodo
logar();
}private void btnEntrarActionPerformed(java.awt.event.ActionEvent evt) {
// chamando o metodo
logar();
}/**
-
@param args the command line arguments
/
public static void main(String args[]) {
/ Set the Nimbus look and feel /
//
/ 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(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//
- For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Login().setVisible(true);
}
});
}// Variables declaration - do not modify
private javax.swing.JButton btnEntrar;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel lblFundo;
private javax.swing.JLabel lblStatus;
private javax.swing.JTextField txtCpf;
private javax.swing.JPasswordField txtSenha;
// End of variables declaration
} - Creates new form Login