Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 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 crud;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JOptionPane;
- /**
- *
- * @author gbastos-inf152
- */
- public class NewJFrame extends javax.swing.JFrame {
- /**
- * Creates new form NewJFrame
- */
- public NewJFrame() {
- initComponents();
- }
- /**
- * 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")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jPanel1 = new javax.swing.JPanel();
- jLabel1 = new javax.swing.JLabel();
- jTextField1 = new javax.swing.JTextField();
- jLabel3 = new javax.swing.JLabel();
- jLabel4 = new javax.swing.JLabel();
- jLabel5 = new javax.swing.JLabel();
- jLabel6 = new javax.swing.JLabel();
- jLabel7 = new javax.swing.JLabel();
- jLabel8 = new javax.swing.JLabel();
- jLabel9 = new javax.swing.JLabel();
- jLabel10 = new javax.swing.JLabel();
- jLabel11 = new javax.swing.JLabel();
- jLabel12 = new javax.swing.JLabel();
- jLabel13 = new javax.swing.JLabel();
- jLabel14 = new javax.swing.JLabel();
- jPasswordField1 = new javax.swing.JPasswordField();
- jTextField2 = new javax.swing.JTextField();
- jTextField3 = new javax.swing.JTextField();
- jTextField4 = new javax.swing.JTextField();
- jTextField5 = new javax.swing.JTextField();
- jTextField6 = new javax.swing.JTextField();
- jComboBox1 = new javax.swing.JComboBox();
- jTextField7 = new javax.swing.JTextField();
- jTextField8 = new javax.swing.JTextField();
- jTextField10 = new javax.swing.JTextField();
- jTextField11 = new javax.swing.JTextField();
- jLabel15 = new javax.swing.JLabel();
- jTextField12 = new javax.swing.JTextField();
- jComboBox2 = new javax.swing.JComboBox();
- jButton1 = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
- jButton3 = new javax.swing.JButton();
- jButton4 = new javax.swing.JButton();
- jButton5 = new javax.swing.JButton();
- jButton6 = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- getContentPane().setLayout(null);
- jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
- jLabel1.setText("Codigo");
- jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(21, 28, -1, -1));
- jTextField1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jTextField1ActionPerformed(evt);
- }
- });
- jPanel1.add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 30, 95, -1));
- jLabel3.setText("Nome");
- jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(21, 63, -1, -1));
- jLabel4.setText("Endereco");
- jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(21, 95, -1, -1));
- jLabel5.setText("Cidade");
- jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(21, 145, -1, -1));
- jLabel6.setText("Cep");
- jPanel1.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 190, -1, -1));
- jLabel7.setText("Estado Civil");
- jPanel1.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 260, -1, -1));
- jLabel8.setText("Email");
- jPanel1.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(21, 293, -1, -1));
- jLabel9.setText("Bairro");
- jPanel1.add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(221, 154, -1, -1));
- jLabel10.setText("Fone:");
- jPanel1.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(221, 186, -1, -1));
- jLabel11.setText("UF");
- jPanel1.add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(346, 154, -1, -1));
- jLabel12.setText("Cel:");
- jPanel1.add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(346, 186, -1, -1));
- jLabel13.setText("Login");
- jPanel1.add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 450, -1, -1));
- jLabel14.setText("Senha");
- jPanel1.add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 450, -1, -1));
- jPasswordField1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jPasswordField1ActionPerformed(evt);
- }
- });
- jPanel1.add(jPasswordField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 450, 120, -1));
- jTextField2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jTextField2ActionPerformed(evt);
- }
- });
- jPanel1.add(jTextField2, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 60, 360, 20));
- jPanel1.add(jTextField3, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 100, 360, 20));
- jPanel1.add(jTextField4, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 140, 140, 20));
- jPanel1.add(jTextField5, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 190, 140, 20));
- jPanel1.add(jTextField6, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 150, 80, 20));
- jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
- jPanel1.add(jComboBox1, new org.netbeans.lib.awtextra.AbsoluteConstraints(370, 150, -1, -1));
- jPanel1.add(jTextField7, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 180, 80, 20));
- jPanel1.add(jTextField8, new org.netbeans.lib.awtextra.AbsoluteConstraints(370, 180, 60, 20));
- jPanel1.add(jTextField10, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 290, 170, 20));
- jPanel1.add(jTextField11, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 450, 120, 20));
- jLabel15.setText("Obs:");
- jPanel1.add(jLabel15, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 350, -1, -1));
- jTextField12.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jTextField12ActionPerformed(evt);
- }
- });
- jPanel1.add(jTextField12, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 330, 340, 110));
- jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Casado", "Solteiro", "Separado" }));
- jComboBox2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jComboBox2ActionPerformed(evt);
- }
- });
- jPanel1.add(jComboBox2, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 260, 170, 20));
- jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/1469163587_search.png"))); // NOI18N
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jPanel1.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 30, 70, 60));
- jButton2.setText("adicionar button 1");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- jPanel1.add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 100, 70, 60));
- jButton3.setText("alterar");
- jButton3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton3ActionPerformed(evt);
- }
- });
- jPanel1.add(jButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 170, 70, 50));
- jButton4.setText("nbutton3");
- jButton4.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton4ActionPerformed(evt);
- }
- });
- jPanel1.add(jButton4, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 230, 70, 60));
- jButton5.setText("limpa");
- jButton5.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton5ActionPerformed(evt);
- }
- });
- jPanel1.add(jButton5, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 300, 70, 60));
- jButton6.setText("jButton6");
- jButton6.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton6ActionPerformed(evt);
- }
- });
- jPanel1.add(jButton6, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 370, 70, 60));
- getContentPane().add(jPanel1);
- jPanel1.setBounds(0, 0, 670, 540);
- pack();
- }// </editor-fold>
- private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jTextField12ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- }
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- try{
- Connection con;
- con = DriverManager.getConnection("jdbc:mysql://127.0.0.1/alunos_crud_java","alunos","alunos");
- String sql;
- sql = "INSERT INTO tb_alunos set (nome,endereco,bairro,cep,cidade,estado,fone,cel,estadocivil,"
- + "email,obs,login,senha)VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)";
- PreparedStatement ps;
- ps = con.prepareStatement (sql);
- ps.setString(1, jTextField1.getText());
- ps.setString(2, jTextField2.getText());
- ps.setString(3, jTextField3.getText());
- ps.setString(4, jTextField4.getText());
- ps.setString(5, jTextField5.getText());
- ps.setString(6, jComboBox1.getSelectedItem().toString());
- ps.setString(7, jTextField7.getText());
- ps.setString(8, jTextField8.getText());
- ps.setString(9, jComboBox2.getSelectedItem().toString());
- ps.setString(10, jTextField10.getText());
- ps.setString(12, jTextField12.getText());
- ps.setString(11, jTextField11.getText());
- ps.setString(13, jPasswordField1.getText());
- int res = ps.executeUpdate();
- if (res > 0) {
- JOptionPane.showMessageDialog(null, "Cadastro efetuado com sucesso");}
- else {
- JOptionPane.showMessageDialog(null, "Falha no casdastro");}
- }
- catch (SQLException ex)
- {
- JOptionPane.showMessageDialog(null, "SQLException: " );JOptionPane.showMessageDialog(null, "SQLException: "
- + ex.getMessage () + "\nSQLState: " + ex.getSQLState() + "\nVendorError: " + ex.getErrorCode());
- }
- } // TODO add your handling code here:
- private void PreparedStatement(String sql) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
- try{
- Class.forName("com.mysql.jbdc.Driver");
- Connection con;
- con = DriverManager.getConnection("jbdc:mysql://localhost:3306/projeto_crud_java","alunos","alunos");
- String sql;
- sql = "UPDATE cad_alunos set Nome = ?,Endereco=?,Bairro=?,CEP=?,Cidade=?,Estado=?,Fone=?,CEL=?,estadocivil=?,"
- + "Email=?,Obs=?,login = ? where ID_alunos = ?";
- PreparedStatement ps;
- ps = con.prepareStatement (sql);
- ps.setString(1, jTextField1.getText());
- ps.setString(2, jTextField2.getText());
- ps.setString(3, jTextField3.getText());
- ps.setString(4, jTextField4.getText());
- ps.setString(5, jTextField5.getText());
- ps.setString(6, jComboBox1.getSelectedItem().toString());
- ps.setString(7, jTextField7.getText());
- ps.setString(8, jTextField8.getText());
- ps.setString(9, jComboBox2.getSelectedItem().toString());
- ps.setString(10, jTextField10.getText());
- ps.setString(12, jTextField12.getText());
- ps.setString(11, jTextField11.getText());
- ps.setString(1, jTextField1.getText());
- int res = ps.executeUpdate();
- if (res > 0) {
- JOptionPane.showMessageDialog(null, "Alterado com sucesso");}
- else {
- JOptionPane.showMessageDialog(null, "Nenhum registro alterado");}
- } catch (SQLException ex)
- {
- JOptionPane.showMessageDialog(null, "SQLException: " + ex.getMessage () + "\nSQLState: " + ex.getSQLState() + "\nVendorError: " + ex.getErrorCode());
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(JFRCurso.class.getName()).log(Level.SEVERE,null, ex);
- } // TODO add your handling code here:
- }
- private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
- try{
- Connection con;
- con = DriverManager.getConnection("jbdc:mysql://127.0.01/Nome_Banco","alunos","alunos");
- String sql;//string para receber a script
- sql = "INSERT INTO cad_alunos(campo1,campo2,campo3)VALUES (?,?,?)";
- /*
- */
- PreparedStatement ps;
- ps = con.prepareStatement(sql);
- ps.setString(1, jTextField2.getText());
- ps.setString(2, jTextField4.getText());
- ps.setString(3, jTextField6.getText());
- int res = ps.executeUpdate();
- if (res>0){
- JOptionPane.showMessageDialog(null, "Cadastro efetuado com sucesso");}
- else{
- JOptionPane.showMessageDialog(null, "falha no cadastro");}
- }
- catch (SQLException ex) //Se ocorrer algum erro uma mesangem e exibida.
- {
- JOptionPane.showMessageDialog(null, "SQLException: ");
- } // TODO add your handling code here:
- }
- private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jPasswordField1ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- /**
- * @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(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.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 NewJFrame().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JButton jButton3;
- private javax.swing.JButton jButton4;
- private javax.swing.JButton jButton5;
- private javax.swing.JButton jButton6;
- private javax.swing.JComboBox jComboBox1;
- private javax.swing.JComboBox jComboBox2;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel10;
- private javax.swing.JLabel jLabel11;
- private javax.swing.JLabel jLabel12;
- private javax.swing.JLabel jLabel13;
- private javax.swing.JLabel jLabel14;
- private javax.swing.JLabel jLabel15;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JLabel jLabel4;
- private javax.swing.JLabel jLabel5;
- private javax.swing.JLabel jLabel6;
- private javax.swing.JLabel jLabel7;
- private javax.swing.JLabel jLabel8;
- private javax.swing.JLabel jLabel9;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JPasswordField jPasswordField1;
- private javax.swing.JTextField jTextField1;
- private javax.swing.JTextField jTextField10;
- private javax.swing.JTextField jTextField11;
- private javax.swing.JTextField jTextField12;
- private javax.swing.JTextField jTextField2;
- private javax.swing.JTextField jTextField3;
- private javax.swing.JTextField jTextField4;
- private javax.swing.JTextField jTextField5;
- private javax.swing.JTextField jTextField6;
- private javax.swing.JTextField jTextField7;
- private javax.swing.JTextField jTextField8;
- // End of variables declaration
- }
- ////////////////////////////////////
- /*
- * 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 crud;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JOptionPane;
- /**
- *
- * @author gbastos-inf152
- */
- public class NewJFrame extends javax.swing.JFrame {
- /**
- * Creates new form NewJFrame
- */
- public NewJFrame() {
- initComponents();
- }
- /**
- * 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")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jPanel1 = new javax.swing.JPanel();
- jLabel1 = new javax.swing.JLabel();
- jTextField1 = new javax.swing.JTextField();
- jLabel3 = new javax.swing.JLabel();
- jLabel4 = new javax.swing.JLabel();
- jLabel5 = new javax.swing.JLabel();
- jLabel6 = new javax.swing.JLabel();
- jLabel7 = new javax.swing.JLabel();
- jLabel8 = new javax.swing.JLabel();
- jLabel9 = new javax.swing.JLabel();
- jLabel10 = new javax.swing.JLabel();
- jLabel11 = new javax.swing.JLabel();
- jLabel12 = new javax.swing.JLabel();
- jLabel13 = new javax.swing.JLabel();
- jLabel14 = new javax.swing.JLabel();
- jPasswordField1 = new javax.swing.JPasswordField();
- jTextField2 = new javax.swing.JTextField();
- jTextField3 = new javax.swing.JTextField();
- jTextField4 = new javax.swing.JTextField();
- jTextField5 = new javax.swing.JTextField();
- jTextField6 = new javax.swing.JTextField();
- jComboBox1 = new javax.swing.JComboBox();
- jTextField7 = new javax.swing.JTextField();
- jTextField8 = new javax.swing.JTextField();
- jTextField10 = new javax.swing.JTextField();
- jTextField11 = new javax.swing.JTextField();
- jLabel15 = new javax.swing.JLabel();
- jTextField12 = new javax.swing.JTextField();
- jComboBox2 = new javax.swing.JComboBox();
- jButton1 = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
- jButton3 = new javax.swing.JButton();
- jButton4 = new javax.swing.JButton();
- jButton5 = new javax.swing.JButton();
- jButton6 = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- getContentPane().setLayout(null);
- jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
- jLabel1.setText("Codigo");
- jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(21, 28, -1, -1));
- jTextField1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jTextField1ActionPerformed(evt);
- }
- });
- jPanel1.add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 30, 95, -1));
- jLabel3.setText("Nome");
- jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(21, 63, -1, -1));
- jLabel4.setText("Endereco");
- jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(21, 95, -1, -1));
- jLabel5.setText("Cidade");
- jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(21, 145, -1, -1));
- jLabel6.setText("Cep");
- jPanel1.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 190, -1, -1));
- jLabel7.setText("Estado Civil");
- jPanel1.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 260, -1, -1));
- jLabel8.setText("Email");
- jPanel1.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(21, 293, -1, -1));
- jLabel9.setText("Bairro");
- jPanel1.add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(221, 154, -1, -1));
- jLabel10.setText("Fone:");
- jPanel1.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(221, 186, -1, -1));
- jLabel11.setText("UF");
- jPanel1.add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(346, 154, -1, -1));
- jLabel12.setText("Cel:");
- jPanel1.add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(346, 186, -1, -1));
- jLabel13.setText("Login");
- jPanel1.add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 450, -1, -1));
- jLabel14.setText("Senha");
- jPanel1.add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 450, -1, -1));
- jPasswordField1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jPasswordField1ActionPerformed(evt);
- }
- });
- jPanel1.add(jPasswordField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 450, 120, -1));
- jTextField2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jTextField2ActionPerformed(evt);
- }
- });
- jPanel1.add(jTextField2, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 60, 360, 20));
- jPanel1.add(jTextField3, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 100, 360, 20));
- jPanel1.add(jTextField4, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 140, 140, 20));
- jPanel1.add(jTextField5, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 190, 140, 20));
- jPanel1.add(jTextField6, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 150, 80, 20));
- jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
- jPanel1.add(jComboBox1, new org.netbeans.lib.awtextra.AbsoluteConstraints(370, 150, -1, -1));
- jPanel1.add(jTextField7, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 180, 80, 20));
- jPanel1.add(jTextField8, new org.netbeans.lib.awtextra.AbsoluteConstraints(370, 180, 60, 20));
- jPanel1.add(jTextField10, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 290, 170, 20));
- jPanel1.add(jTextField11, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 450, 120, 20));
- jLabel15.setText("Obs:");
- jPanel1.add(jLabel15, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 350, -1, -1));
- jTextField12.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jTextField12ActionPerformed(evt);
- }
- });
- jPanel1.add(jTextField12, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 330, 340, 110));
- jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Casado", "Solteiro", "Separado" }));
- jComboBox2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jComboBox2ActionPerformed(evt);
- }
- });
- jPanel1.add(jComboBox2, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 260, 170, 20));
- jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/1469163587_search.png"))); // NOI18N
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jPanel1.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 30, 70, 60));
- jButton2.setText("adicionar button 1");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- jPanel1.add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 100, 70, 60));
- jButton3.setText("alterar");
- jButton3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton3ActionPerformed(evt);
- }
- });
- jPanel1.add(jButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 170, 70, 50));
- jButton4.setText("nbutton3");
- jButton4.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton4ActionPerformed(evt);
- }
- });
- jPanel1.add(jButton4, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 230, 70, 60));
- jButton5.setText("limpa");
- jButton5.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton5ActionPerformed(evt);
- }
- });
- jPanel1.add(jButton5, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 300, 70, 60));
- jButton6.setText("jButton6");
- jButton6.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton6ActionPerformed(evt);
- }
- });
- jPanel1.add(jButton6, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 370, 70, 60));
- getContentPane().add(jPanel1);
- jPanel1.setBounds(0, 0, 670, 540);
- pack();
- }// </editor-fold>
- private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jTextField12ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- }
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- try{
- Connection con;
- con = DriverManager.getConnection("jdbc:mysql://127.0.0.1/alunos_crud_java","alunos","alunos");
- String sql;
- sql = "INSERT INTO tb_alunos set (nome,endereco,bairro,cep,cidade,estado,fone,cel,estadocivil,"
- + "email,obs,login,senha)VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)";
- PreparedStatement ps;
- ps = con.prepareStatement (sql);
- ps.setString(1, jTextField1.getText());
- ps.setString(2, jTextField2.getText());
- ps.setString(3, jTextField3.getText());
- ps.setString(4, jTextField4.getText());
- ps.setString(5, jTextField5.getText());
- ps.setString(6, jComboBox1.getSelectedItem().toString());
- ps.setString(7, jTextField7.getText());
- ps.setString(8, jTextField8.getText());
- ps.setString(9, jComboBox2.getSelectedItem().toString());
- ps.setString(10, jTextField10.getText());
- ps.setString(12, jTextField12.getText());
- ps.setString(11, jTextField11.getText());
- ps.setString(13, jPasswordField1.getText());
- int res = ps.executeUpdate();
- if (res > 0) {
- JOptionPane.showMessageDialog(null, "Cadastro efetuado com sucesso");}
- else {
- JOptionPane.showMessageDialog(null, "Falha no casdastro");}
- }
- catch (SQLException ex)
- {
- JOptionPane.showMessageDialog(null, "SQLException: " );JOptionPane.showMessageDialog(null, "SQLException: "
- + ex.getMessage () + "\nSQLState: " + ex.getSQLState() + "\nVendorError: " + ex.getErrorCode());
- }
- } // TODO add your handling code here:
- private void PreparedStatement(String sql) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
- try{
- Class.forName("com.mysql.jbdc.Driver");
- Connection con;
- con = DriverManager.getConnection("jbdc:mysql://localhost:3306/projeto_crud_java","alunos","alunos");
- String sql;
- sql = "UPDATE td_alunos set nome = ?,Endereco=?,Bairro=?,CEP=?,Cidade=?,Estado=?,Fone=?,CEL=?,estadocivil=?,"
- + "Email=?,Obs=?,login = ? where ID_alunos = ?";
- PreparedStatement ps;
- ps = con.prepareStatement (sql);
- ps.setString(1, jTextField1.getText());
- ps.setString(2, jTextField2.getText());
- ps.setString(3, jTextField3.getText());
- ps.setString(4, jTextField4.getText());
- ps.setString(5, jTextField5.getText());
- ps.setString(6, jComboBox1.getSelectedItem().toString());
- ps.setString(7, jTextField7.getText());
- ps.setString(8, jTextField8.getText());
- ps.setString(9, jComboBox2.getSelectedItem().toString());
- ps.setString(10, jTextField10.getText());
- ps.setString(12, jTextField12.getText());
- ps.setString(11, jTextField11.getText());
- ps.setString(1, jTextField1.getText());
- int res = ps.executeUpdate();
- if (res > 0) {
- JOptionPane.showMessageDialog(null, "Alterado com sucesso");}
- else {
- JOptionPane.showMessageDialog(null, "Nenhum registro alterado");}
- } catch (SQLException ex)
- {
- JOptionPane.showMessageDialog(null, "SQLException: " + ex.getMessage () + "\nSQLState: " + ex.getSQLState() + "\nVendorError: " + ex.getErrorCode());
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(JFRCurso.class.getName()).log(Level.SEVERE, null, ex);
- } // TODO add your handling code here:
- }
- private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
- try{
- Class.forName("com.mysql.jbdc.Driver");
- Connection con;
- con = DriverManager.getConnection("jbdc:mysql://127.0.01/Nome_Banco","alunos","alunos");
- String sql = "Select * from cad_alunos Where ID_alunos =? ";
- PreparedStatement ps = con.prepareStatement(sql);
- ps.setString(1, JTextField1.getText());
- ResultSet rs;
- rs = ps.execuseQuery();
- if (rs.next ()) {
- jTextField2.setText(rs.getString("nome"));
- jTextField2.setText(rs.getString("endereco"));
- jTextField2.setText(rs.getString("cidade"));
- jTextField2.setText(rs.getString("bairro"));
- jComboBox1.setSelectedItem(rs.getString("estado"));
- jTextField6.setText(rs.getString("cep"));
- jTextField7.setText(rs.getString("fone"));
- jTextField8.setText(rs.getString("cel"));
- jTextField9.setText(rs.getString("email"));
- jTextField11.setText(rs.getString("obs"));
- }else{
- JOptionPane.showMessageDialog(null, "Registro nao encontrado", "Mensagem", JOptionPane.WARNING_MESSAGE);
- }
- } catch (SQLException ex)
- {
- JOptionPane.showMessageDialog(null, "SQLException: " + ex.getMessage () + "\nSQLState: " + ex.getSQLState() + "\nVendorError: " + ex.getErrorCode());
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(JFRCurso.class.getName()).log(Level.SEVERE, null, ex);
- } // TODO add your handling code here:
- }
- }
- catch (SQLException ex) //Se ocorrer algum erro uma mesangem e exibida.
- {
- JOptionPane.showMessageDialog(null, "SQLException: ");
- } // TODO add your handling code here:
- }
- private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jPasswordField1ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- /**
- * @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(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.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 NewJFrame().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JButton jButton3;
- private javax.swing.JButton jButton4;
- private javax.swing.JButton jButton5;
- private javax.swing.JButton jButton6;
- private javax.swing.JComboBox jComboBox1;
- private javax.swing.JComboBox jComboBox2;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel10;
- private javax.swing.JLabel jLabel11;
- private javax.swing.JLabel jLabel12;
- private javax.swing.JLabel jLabel13;
- private javax.swing.JLabel jLabel14;
- private javax.swing.JLabel jLabel15;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JLabel jLabel4;
- private javax.swing.JLabel jLabel5;
- private javax.swing.JLabel jLabel6;
- private javax.swing.JLabel jLabel7;
- private javax.swing.JLabel jLabel8;
- private javax.swing.JLabel jLabel9;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JPasswordField jPasswordField1;
- private javax.swing.JTextField jTextField1;
- private javax.swing.JTextField jTextField10;
- private javax.swing.JTextField jTextField11;
- private javax.swing.JTextField jTextField12;
- private javax.swing.JTextField jTextField2;
- private javax.swing.JTextField jTextField3;
- private javax.swing.JTextField jTextField4;
- private javax.swing.JTextField jTextField5;
- private javax.swing.JTextField jTextField6;
- private javax.swing.JTextField jTextField7;
- private javax.swing.JTextField jTextField8;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement