Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javacore;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- import javax.swing.JOptionPane;
- /**
- *
- * @author GUSTAVOZLAGO
- */
- public class INCLUIRPRODUCAO extends javax.swing.JFrame {
- /**
- * Creates new form INCLUIRPRODUCAO
- */
- public INCLUIRPRODUCAO() {
- initComponents();
- setSize(800, 600);
- }
- /**
- * 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() {
- jScrollPane1 = new javax.swing.JScrollPane();
- TblIncluirProducao = new javax.swing.JTable();
- btnSalvar = new javax.swing.JButton();
- setResizable(false);
- TblIncluirProducao.setModel(new javax.swing.table.DefaultTableModel(
- new Object [][] {
- {"String", "String", "String", "String"}
- },
- new String [] {
- "DOCUMENTO", "FUNCIONÁRIO", "QUANTIDADE", "DATA"
- }
- ) {
- Class[] types = new Class [] {
- java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
- };
- public Class getColumnClass(int columnIndex) {
- return types [columnIndex];
- }
- });
- TblIncluirProducao.getTableHeader().setReorderingAllowed(false);
- jScrollPane1.setViewportView(TblIncluirProducao);
- if (TblIncluirProducao.getColumnModel().getColumnCount() > 0) {
- TblIncluirProducao.getColumnModel().getColumn(0).setResizable(false);
- TblIncluirProducao.getColumnModel().getColumn(0).setHeaderValue("DOCUMENTO");
- TblIncluirProducao.getColumnModel().getColumn(1).setResizable(false);
- TblIncluirProducao.getColumnModel().getColumn(1).setHeaderValue("FUNCIONÁRIO");
- TblIncluirProducao.getColumnModel().getColumn(2).setResizable(false);
- TblIncluirProducao.getColumnModel().getColumn(2).setHeaderValue("QUANTIDADE");
- TblIncluirProducao.getColumnModel().getColumn(3).setResizable(false);
- TblIncluirProducao.getColumnModel().getColumn(3).setHeaderValue("DATA");
- }
- // btnSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/salvar.png"))); // NOI18N
- btnSalvar.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
- btnSalvar.setMaximumSize(new java.awt.Dimension(100, 100));
- btnSalvar.setMinimumSize(new java.awt.Dimension(100, 100));
- btnSalvar.setPreferredSize(new java.awt.Dimension(100, 100));
- btnSalvar.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnSalvarActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 780, Short.MAX_VALUE)
- .addContainerGap())
- .addGroup(layout.createSequentialGroup()
- .addGap(340, 340, 340)
- .addComponent(btnSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 467, Short.MAX_VALUE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(btnSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap())
- );
- pack();
- setLocationRelativeTo(null);
- }// </editor-fold>
- private void btnSalvarActionPerformed(java.awt.event.ActionEvent evt) {
- int count = 0;
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con;
- con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
- String query = "INSERT INTO incluirproducao (Documento, Funcionario, Quantidade, Data) VALUES(?,?,?,?)";
- try (PreparedStatement stmt = con.prepareStatement(query)) {
- System.out.println(stmt);
- stmt.setString(1, TblIncluirProducao.getModel().getValueAt(count, 0).toString());
- stmt.setString(2, TblIncluirProducao.getModel().getValueAt(count, 0).toString());
- stmt.setString(3, TblIncluirProducao.getModel().getValueAt(count, 0).toString());
- stmt.setString(4, TblIncluirProducao.getModel().getValueAt(count, 0).toString());
- //erro emexecuteUpdate pegar a ultima coluna da tabela do JFrame
- //nullpointer exception
- stmt.executeUpdate();
- }
- con.close();
- this.dispose();
- } catch (ClassNotFoundException ex) {
- System.out.println("Não foi possivel encontrar a classe");
- } catch (SQLException e) {
- JOptionPane.showMessageDialog(this, e.getMessage(), "debug", 1);
- System.out.println("Ocorreu um erro de SQL");
- }
- }
- /**
- * @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(INCLUIRPRODUCAO.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(INCLUIRPRODUCAO.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(INCLUIRPRODUCAO.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(INCLUIRPRODUCAO.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 INCLUIRPRODUCAO().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JTable TblIncluirProducao;
- private javax.swing.JButton btnSalvar;
- private javax.swing.JScrollPane jScrollPane1;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement