Advertisement
gustavozlago

projeto

Apr 27th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.51 KB | None | 0 0
  1. package br.com.gui;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.SQLException;
  7. import javax.swing.JOptionPane;
  8.  
  9. /**
  10.  *
  11.  * @author GUSTAVOZLAGO
  12.  */
  13. public class INCLUIRPRODUCAO extends javax.swing.JFrame {
  14.  
  15.     /**
  16.      * Creates new form INCLUIRPRODUCAO
  17.      */
  18.     public INCLUIRPRODUCAO() {
  19.         initComponents();
  20.         setSize(800, 600);
  21.     }
  22.  
  23.     /**
  24.      * This method is called from within the constructor to initialize the form.
  25.      * WARNING: Do NOT modify this code. The content of this method is always
  26.      * regenerated by the Form Editor.
  27.      */
  28.     @SuppressWarnings("unchecked")
  29.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  30.     private void initComponents() {
  31.  
  32.         jScrollPane1 = new javax.swing.JScrollPane();
  33.         TblIncluirProducao = new javax.swing.JTable();
  34.         btnSalvar = new javax.swing.JButton();
  35.  
  36.         setResizable(false);
  37.  
  38.         TblIncluirProducao.setModel(new javax.swing.table.DefaultTableModel(
  39.             new Object [][] {
  40.                 {null, null, null, null},
  41.                 {null, null, null, null},
  42.                 {null, null, null, null},
  43.                 {null, null, null, null},
  44.                 {null, null, null, null},
  45.                 {null, null, null, null},
  46.                 {null, null, null, null},
  47.                 {null, null, null, null},
  48.                 {null, null, null, null},
  49.                 {null, null, null, null},
  50.                 {null, null, null, null},
  51.                 {null, null, null, null},
  52.                 {null, null, null, null},
  53.                 {null, null, null, null},
  54.                 {null, null, null, null},
  55.                 {null, null, null, null},
  56.                 {null, null, null, null},
  57.                 {null, null, null, null},
  58.                 {null, null, null, null},
  59.                 {null, null, null, null},
  60.                 {null, null, null, null},
  61.                 {null, null, null, null},
  62.                 {null, null, null, null},
  63.                 {null, null, null, null},
  64.                 {null, null, null, null},
  65.                 {null, null, null, null},
  66.                 {null, null, null, null},
  67.                 {null, null, null, null},
  68.                 {null, null, null, null},
  69.                 {null, null, null, null},
  70.                 {null, null, null, null},
  71.                 {null, null, null, null},
  72.                 {null, null, null, null},
  73.                 {null, null, null, null},
  74.                 {null, null, null, null},
  75.                 {null, null, null, null},
  76.                 {null, null, null, null},
  77.                 {null, null, null, null},
  78.                 {null, null, null, null},
  79.                 {null, null, null, null},
  80.                 {null, null, null, null},
  81.                 {null, null, null, null},
  82.                 {null, null, null, null},
  83.                 {null, null, null, null},
  84.                 {null, null, null, null},
  85.                 {null, null, null, null},
  86.                 {null, null, null, null},
  87.                 {null, null, null, null},
  88.                 {null, null, null, null},
  89.                 {null, null, null, null},
  90.                 {null, null, null, null},
  91.                 {null, null, null, null},
  92.                 {null, null, null, null},
  93.                 {null, null, null, null},
  94.                 {null, null, null, null},
  95.                 {null, null, null, null},
  96.                 {null, null, null, null},
  97.                 {null, null, null, null},
  98.                 {null, null, null, null},
  99.                 {null, null, null, null},
  100.                 {null, null, null, null},
  101.                 {null, null, null, null},
  102.                 {null, null, null, null},
  103.                 {null, null, null, null},
  104.                 {null, null, null, null},
  105.                 {null, null, null, null},
  106.                 {null, null, null, null},
  107.                 {null, null, null, null},
  108.                 {null, null, null, null},
  109.                 {null, null, null, null},
  110.                 {null, null, null, null},
  111.                 {null, null, null, null},
  112.                 {null, null, null, null},
  113.                 {null, null, null, null},
  114.                 {null, null, null, null},
  115.                 {null, null, null, null},
  116.                 {null, null, null, null},
  117.                 {null, null, null, null},
  118.                 {null, null, null, null},
  119.                 {null, null, null, null},
  120.                 {null, null, null, null},
  121.                 {null, null, null, null},
  122.                 {null, null, null, null},
  123.                 {null, null, null, null},
  124.                 {null, null, null, null},
  125.                 {null, null, null, null},
  126.                 {null, null, null, null},
  127.                 {null, null, null, null},
  128.                 {null, null, null, null},
  129.                 {null, null, null, null},
  130.                 {null, null, null, null},
  131.                 {null, null, null, null},
  132.                 {null, null, null, null},
  133.                 {null, null, null, null},
  134.                 {null, null, null, null},
  135.                 {null, null, null, null},
  136.                 {null, null, null, null},
  137.                 {null, null, null, null},
  138.                 {null, null, null, null},
  139.                 {null, null, null, null}
  140.             },
  141.             new String [] {
  142.                 "DOCUMENTO", "FUNCIONÁRIO", "QUANTIDADE", "DATA"
  143.             }
  144.         ) {
  145.             Class[] types = new Class [] {
  146.                 java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
  147.             };
  148.  
  149.             public Class getColumnClass(int columnIndex) {
  150.                 return types [columnIndex];
  151.             }
  152.         });
  153.         TblIncluirProducao.getTableHeader().setReorderingAllowed(false);
  154.         jScrollPane1.setViewportView(TblIncluirProducao);
  155.         if (TblIncluirProducao.getColumnModel().getColumnCount() > 0) {
  156.             TblIncluirProducao.getColumnModel().getColumn(0).setResizable(false);
  157.             TblIncluirProducao.getColumnModel().getColumn(0).setHeaderValue("DOCUMENTO");
  158.             TblIncluirProducao.getColumnModel().getColumn(1).setResizable(false);
  159.             TblIncluirProducao.getColumnModel().getColumn(1).setHeaderValue("FUNCIONÁRIO");
  160.             TblIncluirProducao.getColumnModel().getColumn(2).setResizable(false);
  161.             TblIncluirProducao.getColumnModel().getColumn(2).setHeaderValue("QUANTIDADE");
  162.             TblIncluirProducao.getColumnModel().getColumn(3).setResizable(false);
  163.             TblIncluirProducao.getColumnModel().getColumn(3).setHeaderValue("DATA");
  164.         }
  165.  
  166.         btnSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/salvar.png"))); // NOI18N
  167.         btnSalvar.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
  168.         btnSalvar.setMaximumSize(new java.awt.Dimension(100, 100));
  169.         btnSalvar.setMinimumSize(new java.awt.Dimension(100, 100));
  170.         btnSalvar.setPreferredSize(new java.awt.Dimension(100, 100));
  171.         btnSalvar.addActionListener(new java.awt.event.ActionListener() {
  172.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  173.                 btnSalvarActionPerformed(evt);
  174.             }
  175.         });
  176.  
  177.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  178.         getContentPane().setLayout(layout);
  179.         layout.setHorizontalGroup(
  180.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  181.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  182.                 .addContainerGap()
  183.                 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 780, Short.MAX_VALUE)
  184.                 .addContainerGap())
  185.             .addGroup(layout.createSequentialGroup()
  186.                 .addGap(340, 340, 340)
  187.                 .addComponent(btnSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  188.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  189.         );
  190.         layout.setVerticalGroup(
  191.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  192.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  193.                 .addContainerGap()
  194.                 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 467, Short.MAX_VALUE)
  195.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  196.                 .addComponent(btnSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  197.                 .addContainerGap())
  198.         );
  199.  
  200.         pack();
  201.         setLocationRelativeTo(null);
  202.     }// </editor-fold>                        
  203.  
  204.     private void btnSalvarActionPerformed(java.awt.event.ActionEvent evt) {                                          
  205.  
  206.         int count = 0;
  207.         try {
  208.  
  209.             Class.forName("com.mysql.jdbc.Driver");
  210.  
  211.             Connection con;
  212.  
  213.             con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Supram", "root", "123");
  214.  
  215.             String query = "INSERT INTO incluirproducao (Documento, Funcionario, Quantidade, Data) VALUES(?,?,?,?)";
  216.  
  217.             try (PreparedStatement stmt = con.prepareStatement(query)) {
  218.                 while (count < 100) {
  219.  
  220.                     stmt.setString(1, TblIncluirProducao.getModel().getValueAt(count, 0).toString());
  221.                     stmt.setString(2, TblIncluirProducao.getModel().getValueAt(count, 1).toString());
  222.                     stmt.setString(3, TblIncluirProducao.getModel().getValueAt(count, 2).toString());
  223.                     stmt.setString(4, TblIncluirProducao.getModel().getValueAt(count, 3).toString());
  224.  
  225.                     //erro emexecuteUpdate pegar a ultima coluna da tabela do JFrame
  226.                     //nullpointer exception
  227.                     stmt.executeUpdate();
  228.  
  229.                     count++;
  230.                 }
  231.             }
  232.             con.close();
  233.             this.dispose();
  234.  
  235.         } catch (ClassNotFoundException ex) {
  236.             System.out.println("Não foi possivel encontrar a classe");
  237.         } catch (SQLException e) {
  238.             JOptionPane.showMessageDialog(this, e.getMessage(), "debug", 1);
  239.             System.out.println("Ocorreu um erro de SQL");
  240.         }
  241.  
  242.  
  243.     }                                        
  244.  
  245.     /**
  246.      * @param args the command line arguments
  247.      */
  248.     public static void main(String args[]) {
  249.         /* Set the Nimbus look and feel */
  250.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  251.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  252.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  253.          */
  254.         try {
  255.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  256.                 if ("Nimbus".equals(info.getName())) {
  257.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  258.                     break;
  259.                 }
  260.             }
  261.         } catch (ClassNotFoundException ex) {
  262.             java.util.logging.Logger.getLogger(INCLUIRPRODUCAO.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  263.         } catch (InstantiationException ex) {
  264.             java.util.logging.Logger.getLogger(INCLUIRPRODUCAO.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  265.         } catch (IllegalAccessException ex) {
  266.             java.util.logging.Logger.getLogger(INCLUIRPRODUCAO.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  267.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  268.             java.util.logging.Logger.getLogger(INCLUIRPRODUCAO.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  269.         }
  270.         //</editor-fold>
  271.  
  272.         /* Create and display the form */
  273.         java.awt.EventQueue.invokeLater(new Runnable() {
  274.             public void run() {
  275.                 new INCLUIRPRODUCAO().setVisible(true);
  276.             }
  277.         });
  278.     }
  279.  
  280.     // Variables declaration - do not modify                    
  281.     private javax.swing.JTable TblIncluirProducao;
  282.     private javax.swing.JButton btnSalvar;
  283.     private javax.swing.JScrollPane jScrollPane1;
  284.     // End of variables declaration                  
  285.  
  286. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement