Problema na hora de salvar a jtble e a data no banco de dados

23 respostas
I

Olá pessoal pode me ajudar está faltando alguma coisa no metodo salvar dados que fiz que salva uma jtable e também na data ambos não salvam …
vou postar o codigo ai se alguem puder me ajudar … o banco de dados é o postgres …
Agradeço desde já …

JFRAME CONTROLE PEDIDO
/*

  • To change this template, choose Tools | Templates
  • and open the template in the editor.
    */

/*

  • ControlePedido.java
  • Created on 10/03/2012, 10:50:52
    */
    package Pedido;
import java.util.Date;

import Pagamento.<em>;

import Produto.Produto;

import java.sql.</em>;

import java.text.SimpleDateFormat;

import java.util.logging.Level;

import java.util.logging.Logger;

import javax.swing.JOptionPane;

import javax.swing.JTable;

import sgc.ConectaBanco;

/**
*

  • @author [telefone removido]
    */
    public class ControlePedido extends javax.swing.JFrame {

    Connection conexao = ConectaBanco.getConexao();

    String ativComp[]=
    
    new String []{
    
    null,null,null,null,null
    
    };
    
    int linha;
    
    private double total;
    
    private Date data_save;//
    
    /** Creates new form ControlePedido */
    
    public ControlePedido() throws SQLException, ClassNotFoundException {
    
    initComponents();
     getdata();
    

    }

    private void getdata(){
    
    data_save = new Date();//
    
    StringBuilder data = new StringBuilder(); //StringBuffer data = new StringBuffer();
    
    SimpleDateFormat sdfData = new SimpleDateFormat(yyyy-MM-dd);// (“dd/MM/yyyy”);//
    
    data.append(sdfData.format(data_save));
    
    jt_data.setText(data.toString());
    
    }
    

    /** 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() {
      
      jPanel1 = new javax.swing.JPanel();
      
      jLabel1 = new javax.swing.JLabel();
      
      jScrollPane1 = new javax.swing.JScrollPane();
      
      jTable1 = new javax.swing.JTable();
      
      jLabel2 = new javax.swing.JLabel();
      
      jt_total = new javax.swing.JTextField();
      
      jLabel3 = new javax.swing.JLabel();
      
      jb_cancelar = new javax.swing.JButton();
      
      jb_salvar = new javax.swing.JButton();
      
      jt_codigo = new javax.swing.JTextField();
      
      jt_data = new javax.swing.JTextField();
      
      jt_nome = new javax.swing.JTextField();
      
      jLabel4 = new javax.swing.JLabel();
      
      jb_ok = new javax.swing.JButton();
      
      jb_confirmar = new javax.swing.JButton();
      

      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

      jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, “Pedido”, javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font(“Tahoma”, 1, 11))); // NOI18N

      jLabel1.setText(“Codigo_Pedido:”);

      jTable1.setForeground(new java.awt.Color(102, 102, 0));
      
      jTable1.setModel(new javax.swing.table.DefaultTableModel(
      
      new Object [][] {
      
      {null, null, null, null, null},
      
      {null, null, null, null, null},
      
      {null, null, null, null, null},
      
      {null, null, null, null, null},
      
      {null, null, null, null, null},
      
      {null, null, null, null, null},
      
      {null, null, null, null, null}
      
      },
      
      new String [] {
      
      Codigo, Produto, Qtde, Valor Unitario, Valor Total
      
      }
      
      ) {
      
      boolean[] canEdit = new boolean [] {
      
      false, false, true, false, false
      
      };
      
      public boolean isCellEditable(int rowIndex, int columnIndex) {
           return canEdit [columnIndex];
       }
      
      });
      
      jTable1.getTableHeader().setReorderingAllowed(false);
      
      jTable1.addFocusListener(new java.awt.event.FocusAdapter() {
      
      public void focusLost(java.awt.event.FocusEvent evt) {
      
      jTable1FocusLost(evt);
      
      }
      
      });
      
      jTable1.addAncestorListener(new javax.swing.event.AncestorListener() {
      
      public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
      
      }
      
      public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
      
      jTable1AncestorAdded(evt);
      
      }
      
      public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
      
      }
      
      });
      
      jTable1.addKeyListener(new java.awt.event.KeyAdapter() {
      
      public void keyPressed(java.awt.event.KeyEvent evt) {
      
      jTable1KeyPressed(evt);
      
      }
      
      });
      
      jScrollPane1.setViewportView(jTable1);
      

      jLabel2.setText(“Total:”);

      jt_total.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jt_totalActionPerformed(evt);
      
      }
      
      });
      

      jLabel3.setText(“Data:”);

      jb_cancelar.setBackground(javax.swing.UIManager.getDefaults().getColor(“Button.light”));
      
      jb_cancelar.setText(“Cancelar”);
      
      jb_cancelar.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jb_cancelarActionPerformed(evt);
      
      }
      
      });
      
      jb_salvar.setBackground(javax.swing.UIManager.getDefaults().getColor(Button.light));
      
      jb_salvar.setText(Salvar);
      
      jb_salvar.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jb_salvarActionPerformed(evt);
      
      }
      
      });
      
      jt_codigo.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jt_codigoActionPerformed(evt);
      
      }
      
      });
      

      jt_data.setEditable(false);

      jt_nome.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jt_nomeActionPerformed(evt);
      
      }
      
      });
      

      jLabel4.setText(“Produto:”);

      jb_ok.setText(“Ok”);
      
      jb_ok.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jb_okActionPerformed(evt);
      
      }
      
      });
      
      jb_ok.addFocusListener(new java.awt.event.FocusAdapter() {
      
      public void focusLost(java.awt.event.FocusEvent evt) {
      
      jb_okFocusLost(evt);
      
      }
      
      });
      
      jb_confirmar.setText(“Confirmar”);
      
      jb_confirmar.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jb_confirmarActionPerformed(evt);
      
      }
      
      });
      
      javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
      
      jPanel1.setLayout(jPanel1Layout);
      
      jPanel1Layout.setHorizontalGroup(
      
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addGroup(jPanel1Layout.createSequentialGroup()
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
      
      .addGroup(jPanel1Layout.createSequentialGroup()
      
      .addGap(11, 11, 11)
      
      .addComponent(jLabel1)
      
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
      
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
      
      .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      
      .addComponent(jLabel4)
      
      .addGap(16, 16, 16)))
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addGroup(jPanel1Layout.createSequentialGroup()
      
      .addComponent(jt_nome, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addGap(18, 18, 18)
      
      .addComponent(jb_ok)
      
      .addContainerGap())
      
      .addGroup(jPanel1Layout.createSequentialGroup()
      
      .addComponent(jt_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 165, Short.MAX_VALUE)
      
      .addComponent(jLabel3)
      
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      
      .addComponent(jt_data, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addGap(26, 26, 26))))
      
      .addGroup(jPanel1Layout.createSequentialGroup()
      
      .addContainerGap()
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addGroup(jPanel1Layout.createSequentialGroup()
      
      .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 485, Short.MAX_VALUE)
      
      .addContainerGap())
      
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
      
      .addGap(0, 0, Short.MAX_VALUE)
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
      
      .addComponent(jLabel2)
      
      .addGap(18, 18, 18)
      
      .addComponent(jt_total, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addGap(43, 43, 43))
      
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
      
      .addComponent(jb_salvar, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addGap(18, 18, 18)
      
      .addComponent(jb_cancelar)
      
      .addGap(18, 18, 18)
      
      .addComponent(jb_confirmar)
      
      .addGap(127, 127, 127))))))
      
      );
      
      jPanel1Layout.setVerticalGroup(
      
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addGroup(jPanel1Layout.createSequentialGroup()
      
      .addContainerGap()
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      
      .addComponent(jLabel1)
      
      .addComponent(jLabel3)
      
      .addComponent(jt_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addComponent(jt_data, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
      
      .addGap(18, 18, 18)
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      
      .addComponent(jt_nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addComponent(jLabel4)
      
      .addComponent(jb_ok))
      
      .addGap(6, 6, 6)
      
      .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      
      .addComponent(jt_total, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addComponent(jLabel2))
      
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      
      .addComponent(jb_confirmar)
      
      .addComponent(jb_cancelar)
      
      .addComponent(jb_salvar))
      
      .addContainerGap())
      
      );
      
      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(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      
      .addContainerGap())
      
      );
      
      layout.setVerticalGroup(
      
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addGroup(layout.createSequentialGroup()
      
      .addContainerGap()
      
      .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      
      .addContainerGap())
      
      );
      

      pack();
      }//

    private void jt_totalActionPerformed(java.awt.event.ActionEvent evt) {
    
    Pedido pedido= new Pedido();
    
    jt_total.setText(String.valueOf(pedido.calcularTotal(pedido.getValorTotal())));        // TODO add your handling code here:
    
    }
    

    private void jb_salvarActionPerformed(java.awt.event.ActionEvent evt) {

    try {
         
         Pedido pedido = new Pedido();
         PedidoDao ped = new PedidoDao();
    
         int codigo = Integer.parseInt(jt_codigo.getText());
         String data = String.valueOf(jt_data.getText());//long data = Date.parse(jt_data.getText());
         Double valorTotal = Double.parseDouble(jt_total.getText());
    
    
         pedido.setCodigo(codigo);
         pedido.setData(data_save);
         pedido.setValorTotal(valorTotal);
    
         ped.realizar(pedido);
     
    
     } catch (Exception ex) {
         System.out.print("Erro ao salvar o pedido "+ex);
     }
      JOptionPane.showMessageDialog(null, "Orçamento salvo com sucesso !!!");
    

    }

    private void jb_cancelarActionPerformed(java.awt.event.ActionEvent evt) {
    
    // TODO add your handling code here:
    
    JOptionPane.showMessageDialog(null, Deseja cancelar essa venda?”);
    
    this.dispose();
    
    }
    
private void jTable1FocusLost(java.awt.event.FocusEvent evt) {

// TODO add your handling code here:

}

private void jt_nomeActionPerformed(java.awt.event.ActionEvent evt) {

}

private void jt_codigoActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

}
private void jb_okActionPerformed(java.awt.event.ActionEvent evt) {                                      
       
    
    try {
        informacaoPadrao();
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(ControlePedido.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
        Logger.getLogger(ControlePedido.class.getName()).log(Level.SEVERE, null, ex);
    }

    insereDadosTabela(ativComp,linha);
   
}                                     

private void jb_okFocusLost(java.awt.event.FocusEvent evt) {                                
          //jTable1.(ativComp);
        // jt_preco.setText(String.valueOf(produto.calcularPreco(produto.getPrecoCusto())));
}                               

private void jb_confirmarActionPerformed(java.awt.event.ActionEvent evt) {                                             
    // TODO add your handling code here:
    ControlePagamento cp2 = new ControlePagamento();
    cp2.setVisible(true);
}                                            

private void jTable1AncestorAdded(javax.swing.event.AncestorEvent evt) {                                      
    
}                                     

private void jTable1KeyPressed(java.awt.event.KeyEvent evt) {                                   
    int col = 5;
    total = 0;
    for (int i = 0; i < linha; i++) {
         double x = Integer.parseInt(jTable1.getValueAt(i, 2).toString()) * Double.parseDouble(jTable1.getValueAt(i, 3).toString());
         jTable1.setValueAt(String.valueOf(x),i, 4);
         total = total + x; 
    }
    jt_total.setText(String.valueOf(total));
}                                  


/**
 * @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(ControlePedido.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(ControlePedido.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(ControlePedido.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(ControlePedido.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() {
            try {
                new ControlePedido().setVisible(true);
            } catch (SQLException ex) {
                Logger.getLogger(ControlePedido.class.getName()).log(Level.SEVERE, null, ex);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(ControlePedido.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
}

private void insereDadosTabela(String[] x, int i ) {

    int col = jTable1.getColumnCount();

    for (int j = 0; j < col; j++) {
        jTable1.setValueAt(x[j], i, j);
    }
    linha++;
}


private void informacaoPadrao() throws ClassNotFoundException, SQLException{

    String sql = "select * from produto where nome='" + jt_nome.getText() + "'";

    conexao = ConectaBanco.getConexao();
    PreparedStatement pstmt = conexao.prepareStatement(sql);
        
    ResultSet rs = pstmt.executeQuery();
    
    String coluna1, coluna2;
    int coluna3;
    double coluna4,coluna5 = 0;
    
    try{

        while (rs.next()) {
            coluna1 = rs.getString("codigo");             
            coluna2 = rs.getString("nome");
            coluna3 = rs.getInt("qtd");
            coluna4 = rs.getDouble("preco");
            coluna5 = (coluna3*coluna4);// SEM PARENTESES

            ativComp [0] = coluna1;
            ativComp [1] = coluna2;
            ativComp [2] = String.valueOf(coluna3);
            ativComp [3] = String.valueOf(coluna4);
            ativComp [4] = String.valueOf(coluna5);

        }
        rs.close();
    
    }
    catch (SQLException ex) {
        System.out.println("Problema na conexao com a fonte de dados");
    }

    jt_total.setText(String.valueOf(total(coluna5)));
}

private double total(double x){
    total = total + x;
    return total;
}

// Variables declaration - do not modify                     
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
private javax.swing.JButton jb_cancelar;
private javax.swing.JButton jb_confirmar;
private javax.swing.JButton jb_ok;
private javax.swing.JButton jb_salvar;
private javax.swing.JTextField jt_codigo;
private javax.swing.JTextField jt_data;
private javax.swing.JTextField jt_nome;
private javax.swing.JTextField jt_total;
// End of variables declaration

}

CLASSE PEDIDO
package Pedido;

import java.util.Date;

public class Pedido {

private int codigo;

private double valorTotal;

private Date data;
public Date getData() {
    return data;
}

public void setData(Date data) {
    this.data = data;
}


public int getCodigo() {
    return codigo;
}


public void setCodigo(int codigo) {
    this.codigo = codigo;
}

public double getValorTotal() {
    return valorTotal;
}

public void setValorTotal(double valorTotal) {
    this.valorTotal = valorTotal;
}


public double calcularTotal(double valorTotal){
    double total=0;
    
    total= total + valorTotal;
    return (total);
}

}

CLASSE PEDIDODAO

/*
  • To change this template, choose Tools | Templates
  • and open the template in the editor.
    */
    package Pedido;
import java.sql.*;

import java.util.ArrayList;

import javax.swing.JOptionPane;

import sgc.ConectaBanco;

import java.sql.Connection;

public class PedidoDao extends Pedido {
private Date parameterIndex;

public void realizar(Pedido pedido) throws ClassNotFoundException, SQLException{
  
      
      Connection conexao = ConectaBanco.getConexao();
      
      String sql="insert into pedido(codigo,data,valorTotal) values(?,?,?)";
      
      PreparedStatement pstmt = conexao.prepareStatement(sql);
      pstmt.setInt(1,pedido.getCodigo());
      pstmt.setDate(2,parameterIndex, null);
      pstmt.setDouble(3,pedido.getValorTotal());
      
     
      pstmt.execute();

      pstmt.close();
      System.out.println("Pedido realizado com sucesso !!!");
 }

}

Agradeço desde já …

23 Respostas

guilherme.dio

Primeiramente, coloque a tag *CODE envolvendo o codigo que voce postar, assim fica mais facil de entendermos.

Ex:

//CODIGO AQUI
I

Ok desculpe sou nova usuaria não sabia …

Mas então pode me ajudar está faltando alguma coisa no metodo salvar dados que fiz que salva uma jtable e também na data ambos não salvam …
o banco de dados é o postgres …
Agradeço desde já …

CODE
//JFRAME CONTROLE PEDIDO
/

  • To change this template, choose Tools | Templates
  • and open the template in the editor.
    /
    /
  • ControlePedido.java
  • Created on 10/03/2012, 10:50:52
    /
    package Pedido;
    import java.util.Date;
    import Pagamento.
    ;
    import Produto.Produto;
    import java.sql.*;
    import java.text.SimpleDateFormat;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.JOptionPane;
    import javax.swing.JTable;
    import sgc.ConectaBanco;

/**
*

  • @author [telefone removido]
    */
    public class ControlePedido extends javax.swing.JFrame {

    Connection conexao = ConectaBanco.getConexao();

    String ativComp[]=
    
    new String []{
    
    null,null,null,null,null
    
    };
    
    int linha;
    
    private double total;
    
    private Date data_save;//
    
    /** Creates new form ControlePedido */
    
    public ControlePedido() throws SQLException, ClassNotFoundException {
    
    initComponents();
     getdata();
    

    }

    private void getdata(){
    
    data_save = new Date();//
    
    StringBuilder data = new StringBuilder(); //StringBuffer data = new StringBuffer();
    
    SimpleDateFormat sdfData = new SimpleDateFormat(yyyy-MM-dd);// (dd/MM/yyyy);//
    
    data.append(sdfData.format(data_save));
    
    jt_data.setText(data.toString());
    
    }
    
    /** 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() {
      
      jPanel1 = new javax.swing.JPanel();
      
      jLabel1 = new javax.swing.JLabel();
      
      jScrollPane1 = new javax.swing.JScrollPane();
      
      jTable1 = new javax.swing.JTable();
      
      jLabel2 = new javax.swing.JLabel();
      
      jt_total = new javax.swing.JTextField();
      
      jLabel3 = new javax.swing.JLabel();
      
      jb_cancelar = new javax.swing.JButton();
      
      jb_salvar = new javax.swing.JButton();
      
      jt_codigo = new javax.swing.JTextField();
      
      jt_data = new javax.swing.JTextField();
      
      jt_nome = new javax.swing.JTextField();
      
      jLabel4 = new javax.swing.JLabel();
      
      jb_ok = new javax.swing.JButton();
      
      jb_confirmar = new javax.swing.JButton();
      
      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
      
      jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, Pedido, javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font(Tahoma, 1, 11))); // NOI18N
      
      jLabel1.setText(Codigo_Pedido:);
      
      jTable1.setForeground(new java.awt.Color(102, 102, 0));
      
      jTable1.setModel(new javax.swing.table.DefaultTableModel(
      
      new Object [][] {
      
      {null, null, null, null, null},
      
      {null, null, null, null, null},
      
      {null, null, null, null, null},
      
      {null, null, null, null, null},
      
      {null, null, null, null, null},
      
      {null, null, null, null, null},
      
      {null, null, null, null, null}
      
      },
      
      new String [] {
      
      Codigo, Produto, Qtde, Valor Unitario, Valor Total
      
      }
      
      ) {
      
      boolean[] canEdit = new boolean [] {
      
      false, false, true, false, false
      
      };
      
      public boolean isCellEditable(int rowIndex, int columnIndex) {
      
      return canEdit [columnIndex];
      
      }
      
      });
      
      jTable1.getTableHeader().setReorderingAllowed(false);
      
      jTable1.addFocusListener(new java.awt.event.FocusAdapter() {
      
      public void focusLost(java.awt.event.FocusEvent evt) {
      
      jTable1FocusLost(evt);
      
      }
      
      });
      
      jTable1.addAncestorListener(new javax.swing.event.AncestorListener() {
      
      public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
      
      }
      
      public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
      
      jTable1AncestorAdded(evt);
      
      }
      
      public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
      
      }
      
      });
      
      jTable1.addKeyListener(new java.awt.event.KeyAdapter() {
      
      public void keyPressed(java.awt.event.KeyEvent evt) {
      
      jTable1KeyPressed(evt);
      
      }
      
      });
      
      jScrollPane1.setViewportView(jTable1);
      
      jLabel2.setText(Total:);
      
      jt_total.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jt_totalActionPerformed(evt);
      
      }
      
      });
      
      jLabel3.setText(Data:);
      
      jb_cancelar.setBackground(javax.swing.UIManager.getDefaults().getColor(Button.light));
      
      jb_cancelar.setText(Cancelar);
      
      jb_cancelar.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jb_cancelarActionPerformed(evt);
      
      }
      
      });
      
      jb_salvar.setBackground(javax.swing.UIManager.getDefaults().getColor(Button.light));
      
      jb_salvar.setText(Salvar);
      
      jb_salvar.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jb_salvarActionPerformed(evt);
      
      }
      
      });
      
      jt_codigo.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jt_codigoActionPerformed(evt);
      
      }
      
      });
      
      jt_data.setEditable(false);
      
      jt_nome.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jt_nomeActionPerformed(evt);
      
      }
      
      });
      
      jLabel4.setText(Produto:);
      
      jb_ok.setText(Ok);
      
      jb_ok.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jb_okActionPerformed(evt);
      
      }
      
      });
      
      jb_ok.addFocusListener(new java.awt.event.FocusAdapter() {
      
      public void focusLost(java.awt.event.FocusEvent evt) {
      
      jb_okFocusLost(evt);
      
      }
      
      });
      
      jb_confirmar.setText(Confirmar);
      
      jb_confirmar.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jb_confirmarActionPerformed(evt);
      
      }
      
      });
      
      javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
      
      jPanel1.setLayout(jPanel1Layout);
      
      jPanel1Layout.setHorizontalGroup(
      
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addGroup(jPanel1Layout.createSequentialGroup()
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
      
      .addGroup(jPanel1Layout.createSequentialGroup()
      
      .addGap(11, 11, 11)
      
      .addComponent(jLabel1)
      
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
      
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
      
      .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      
      .addComponent(jLabel4)
      
      .addGap(16, 16, 16)))
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addGroup(jPanel1Layout.createSequentialGroup()
      
      .addComponent(jt_nome, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addGap(18, 18, 18)
      
      .addComponent(jb_ok)
      
      .addContainerGap())
      
      .addGroup(jPanel1Layout.createSequentialGroup()
      
      .addComponent(jt_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 165, Short.MAX_VALUE)
      
      .addComponent(jLabel3)
      
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      
      .addComponent(jt_data, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addGap(26, 26, 26))))
      
      .addGroup(jPanel1Layout.createSequentialGroup()
      
      .addContainerGap()
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addGroup(jPanel1Layout.createSequentialGroup()
      
      .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 485, Short.MAX_VALUE)
      
      .addContainerGap())
      
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
      
      .addGap(0, 0, Short.MAX_VALUE)
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
      
      .addComponent(jLabel2)
      
      .addGap(18, 18, 18)
      
      .addComponent(jt_total, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addGap(43, 43, 43))
      
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
      
      .addComponent(jb_salvar, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addGap(18, 18, 18)
      
      .addComponent(jb_cancelar)
      
      .addGap(18, 18, 18)
      
      .addComponent(jb_confirmar)
      
      .addGap(127, 127, 127))))))
      
      );
      
      jPanel1Layout.setVerticalGroup(
      
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addGroup(jPanel1Layout.createSequentialGroup()
      
      .addContainerGap()
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      
      .addComponent(jLabel1)
      
      .addComponent(jLabel3)
      
      .addComponent(jt_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addComponent(jt_data, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
      
      .addGap(18, 18, 18)
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      
      .addComponent(jt_nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addComponent(jLabel4)
      
      .addComponent(jb_ok))
      
      .addGap(6, 6, 6)
      
      .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      
      .addComponent(jt_total, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addComponent(jLabel2))
      
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      
      .addComponent(jb_confirmar)
      
      .addComponent(jb_cancelar)
      
      .addComponent(jb_salvar))
      
      .addContainerGap())
      
      );
      
      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(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      
      .addContainerGap())
      
      );
      
      layout.setVerticalGroup(
      
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addGroup(layout.createSequentialGroup()
      
      .addContainerGap()
      
      .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      
      .addContainerGap())
      
      );
      
      pack();
      
      }// 
      
      private void jt_totalActionPerformed(java.awt.event.ActionEvent evt) {
      
      Pedido pedido= new Pedido();
      
      jt_total.setText(String.valueOf(pedido.calcularTotal(pedido.getValorTotal())));        // TODO add your handling code here:
      
      }
      
      private void jb_salvarActionPerformed(java.awt.event.ActionEvent evt) {
      

      try {

      Pedido pedido = new Pedido();
       PedidoDao ped = new PedidoDao();
       int codigo = Integer.parseInt(jt_codigo.getText());
       String data = String.valueOf(jt_data.getText());//long data = Date.parse(jt_data.getText());
       Double valorTotal = Double.parseDouble(jt_total.getText());
      
       pedido.setCodigo(codigo);
       pedido.setData(data_save);
       pedido.setValorTotal(valorTotal);
      
       ped.realizar(pedido);
      
      } catch (Exception ex) {
      
      System.out.print("Erro ao salvar o pedido "+ex);
      
      }
      
      JOptionPane.showMessageDialog(null, Orçamento salvo com sucesso !!!);
      
    }
    
    private void jb_cancelarActionPerformed(java.awt.event.ActionEvent evt) {
    
    // TODO add your handling code here:
    
    JOptionPane.showMessageDialog(null, Deseja cancelar essa venda?”);
    
    this.dispose();
    
    }
    
    private void jTable1FocusLost(java.awt.event.FocusEvent evt) {
    
    // TODO add your handling code here:
    
    }
    
    private void jt_nomeActionPerformed(java.awt.event.ActionEvent evt) {
    
    }
    
    private void jt_codigoActionPerformed(java.awt.event.ActionEvent evt) {
    
    // TODO add your handling code here:
    
    }
    
    private void jb_okActionPerformed(java.awt.event.ActionEvent evt) {
    
    try {
         informacaoPadrao();
     } catch (ClassNotFoundException ex) {
         Logger.getLogger(ControlePedido.class.getName()).log(Level.SEVERE, null, ex);
     } catch (SQLException ex) {
         Logger.getLogger(ControlePedido.class.getName()).log(Level.SEVERE, null, ex);
     }
     insereDadosTabela(ativComp,linha);
    
    }
    
    private void jb_okFocusLost(java.awt.event.FocusEvent evt) {
    
    //jTable1.(ativComp);
    
    // jt_preco.setText(String.valueOf(produto.calcularPreco(produto.getPrecoCusto())));
    
    }
    
    private void jb_confirmarActionPerformed(java.awt.event.ActionEvent evt) {
    
    // TODO add your handling code here:
    
    ControlePagamento cp2 = new ControlePagamento();
    
    cp2.setVisible(true);
    
    }
    
    private void jTable1AncestorAdded(javax.swing.event.AncestorEvent evt) {
    
    }
    
    private void jTable1KeyPressed(java.awt.event.KeyEvent evt) {
    
    int col = 5;
    
    total = 0;
    
    for (int i = 0; i < linha; i++) {
    
    double x = Integer.parseInt(jTable1.getValueAt(i, 2).toString()) * Double.parseDouble(jTable1.getValueAt(i, 3).toString());
    
    jTable1.setValueAt(String.valueOf(x),i, 4);
    
    total = total + x;
    
    }
    
    jt_total.setText(String.valueOf(total));
    
    }
    

    /**

    • @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(ControlePedido.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(ControlePedido.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(ControlePedido.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(ControlePedido.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //
        /
        Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
        try {
        new ControlePedido().setVisible(true);
        } catch (SQLException ex) {
        Logger.getLogger(ControlePedido.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
        Logger.getLogger(ControlePedido.class.getName()).log(Level.SEVERE, null, ex);
        }
        }
        });
        }
        private void insereDadosTabela(String[] x, int i ) {
        int col = jTable1.getColumnCount();
        for (int j = 0; j < col; j++) {
        jTable1.setValueAt(x[j], i, j);
        }
        linha++;
        }
    private void informacaoPadrao() throws ClassNotFoundException, SQLException{
    
    String sql = “select * from produto where nome=’” + jt_nome.getText() + “’”;
    
    conexao = ConectaBanco.getConexao();
    
    PreparedStatement pstmt = conexao.prepareStatement(sql);
    
    ResultSet rs = pstmt.executeQuery();
     
     String coluna1, coluna2;
     int coluna3;
     double coluna4,coluna5 = 0;
     
     try{
         while (rs.next()) {
             coluna1 = rs.getString("codigo");             
             coluna2 = rs.getString("nome");
             coluna3 = rs.getInt("qtd");
             coluna4 = rs.getDouble("preco");
             coluna5 = (coluna3*coluna4);// SEM PARENTESES
             ativComp [0] = coluna1;
             ativComp [1] = coluna2;
             ativComp [2] = String.valueOf(coluna3);
             ativComp [3] = String.valueOf(coluna4);
             ativComp [4] = String.valueOf(coluna5);
         }
         rs.close();
     
     }
     catch (SQLException ex) {
         System.out.println("Problema na conexao com a fonte de dados");
     }
     jt_total.setText(String.valueOf(total(coluna5)));
    

    }

    private double total(double x){
    
    total = total + x;
    
    return total;
    
    }
    
    // Variables declaration - do not modify
    
    private javax.swing.JLabel jLabel1;
    
    private javax.swing.JLabel jLabel2;
    
    private javax.swing.JLabel jLabel3;
    
    private javax.swing.JLabel jLabel4;
    
    private javax.swing.JPanel jPanel1;
    
    private javax.swing.JScrollPane jScrollPane1;
    
    private javax.swing.JTable jTable1;
    
    private javax.swing.JButton jb_cancelar;
    
    private javax.swing.JButton jb_confirmar;
    
    private javax.swing.JButton jb_ok;
    
    private javax.swing.JButton jb_salvar;
    
    private javax.swing.JTextField jt_codigo;
    
    private javax.swing.JTextField jt_data;
    
    private javax.swing.JTextField jt_nome;
    
    private javax.swing.JTextField jt_total;
    
    // End of variables declaration
    
    }
    
//CLASSE PEDIDO

package Pedido;

import java.util.Date;
public class Pedido {

private int codigo;

private double valorTotal;

private Date data;

public Date getData() {

return data;

}

public void setData(Date data) {

this.data = data;

}
public int getCodigo() {
    return codigo;
}

public void setCodigo(int codigo) {
    this.codigo = codigo;
}
public double getValorTotal() {
    return valorTotal;
}
public void setValorTotal(double valorTotal) {
    this.valorTotal = valorTotal;
}

public double calcularTotal(double valorTotal){
    double total=0;
    
    total= total + valorTotal;
    return (total);
}

}

//CLASSE PEDIDODAO

/*
  • To change this template, choose Tools | Templates
  • and open the template in the editor.
    /
    package Pedido;
    import java.sql.
    ;
    import java.util.ArrayList;
    import javax.swing.JOptionPane;
    import sgc.ConectaBanco;
    import java.sql.Connection;

public class PedidoDao extends Pedido {
private Date parameterIndex;

public void realizar(Pedido pedido) throws ClassNotFoundException, SQLException{
  
      
      Connection conexao = ConectaBanco.getConexao();
      
      String sql="insert into pedido(codigo,data,valorTotal) values(?,?,?)";
      
      PreparedStatement pstmt = conexao.prepareStatement(sql);
      pstmt.setInt(1,pedido.getCodigo());
      pstmt.setDate(2,parameterIndex, null);
      pstmt.setDouble(3,pedido.getValorTotal());
      
     
      pstmt.execute();

      pstmt.close();
      System.out.println("Pedido realizado com sucesso !!!");
 }

}

//Agradeço desde já …
*CODE

J

Olá, tu colocou errado a tag de CODE. faz assim:

[*code]
Codigo aqui dentro.
[/*code]

Só remove os asteriscos… :smiley:

I
guilherme.dio:
Primeiramente, coloque a tag *CODE envolvendo o codigo que voce postar, assim fica mais facil de entendermos.

Ex:

//JFRAME CONTROLE PEDIDO 
package Pedido;

import java.util.Date;   
import Pagamento.*;
import Produto.Produto;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import sgc.ConectaBanco;



/**
 *
 * @author [telefone removido]
 */
public class ControlePedido extends javax.swing.JFrame {
    
    
    Connection conexao = ConectaBanco.getConexao();
   

    String ativComp[]=
            new String []{
                null,null,null,null,null
            };
    
    int linha;
    private double total;
    private Date data_save;//
    /** Creates new form ControlePedido */
    public ControlePedido() throws SQLException, ClassNotFoundException {
        
        initComponents();
        getdata();
    }
    
    private void getdata(){
        data_save = new Date();//
        StringBuffer data = new StringBuffer();
        SimpleDateFormat sdfData = new SimpleDateFormat("yyyy-MM-dd");// dd/MM/yyyy
        data.append(sdfData.format(data_save));
        jt_data.setText(data.toString());
    }

    /** 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();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();
        jt_total = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jb_cancelar = new javax.swing.JButton();
        jb_salvar = new javax.swing.JButton();
        jt_codigo = new javax.swing.JTextField();
        jt_data = new javax.swing.JTextField();
        jt_nome = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jb_ok = new javax.swing.JButton();
        jb_confirmar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Pedido", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        jLabel1.setText("Codigo_Pedido:");

        jTable1.setForeground(new java.awt.Color(102, 102, 0));
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Codigo", "Produto", "Qtde", "Valor Unitario", "Valor Total"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, true, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.getTableHeader().setReorderingAllowed(false);
        jTable1.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTable1FocusLost(evt);
            }
        });
        jTable1.addAncestorListener(new javax.swing.event.AncestorListener() {
            public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
            }
            public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
                jTable1AncestorAdded(evt);
            }
            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
            }
        });
        jTable1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTable1KeyPressed(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jLabel2.setText("Total:");

        jt_total.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jt_totalActionPerformed(evt);
            }
        });

        jLabel3.setText("Data:");

        jb_cancelar.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.light"));
        jb_cancelar.setText("Cancelar");
        jb_cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_cancelarActionPerformed(evt);
            }
        });

        jb_salvar.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.light"));
        jb_salvar.setText("Salvar");
        jb_salvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_salvarActionPerformed(evt);
            }
        });

        jt_codigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jt_codigoActionPerformed(evt);
            }
        });

        jt_data.setEditable(false);

        jt_nome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jt_nomeActionPerformed(evt);
            }
        });

        jLabel4.setText("Produto:");

        jb_ok.setText("Ok");
        jb_ok.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_okActionPerformed(evt);
            }
        });
        jb_ok.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jb_okFocusLost(evt);
            }
        });

        jb_confirmar.setText("Confirmar");
        jb_confirmar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_confirmarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel4)
                        .addGap(16, 16, 16)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jt_nome, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jb_ok)
                        .addContainerGap())
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jt_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 165, Short.MAX_VALUE)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jt_data, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(26, 26, 26))))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 485, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(18, 18, 18)
                                .addComponent(jt_total, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(43, 43, 43))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jb_salvar, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jb_cancelar)
                                .addGap(18, 18, 18)
                                .addComponent(jb_confirmar)
                                .addGap(127, 127, 127))))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel3)
                    .addComponent(jt_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jt_data, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jt_nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(jb_ok))
                .addGap(6, 6, 6)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jt_total, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jb_confirmar)
                    .addComponent(jb_cancelar)
                    .addComponent(jb_salvar))
                .addContainerGap())
        );

        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(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>                        

    private void jt_totalActionPerformed(java.awt.event.ActionEvent evt) {                                         
        Pedido pedido= new Pedido();
        jt_total.setText(String.valueOf(pedido.calcularTotal(pedido.getTotal())));        // TODO add your handling code here:
    }                                        

    private void jb_salvarActionPerformed(java.awt.event.ActionEvent evt) {                                          
        
       
        
        try {
            
            Pedido pedido = new Pedido();
            PedidoDao ped = new PedidoDao();

            int codigo = Integer.parseInt(jt_codigo.getText());
            String data = String.valueOf(jt_data.getText());//long data = Date.parse(jt_data.getText());
            double Total = Double.parseDouble(jt_total.getText());


            pedido.setCodigo(codigo);
            pedido.setTotal(Total);
            pedido.setData(data_save);
            
       
            ped.realizar(pedido);
            salvarDados();
        

        } catch (Exception ex) {
            System.out.print("Erro ao salvar o pedido "+ex);
        }
         JOptionPane.showMessageDialog(null, "Orçamento salvo com sucesso !!!");  
      
      
      
            
            
            
          
    }                                         

    private void jb_cancelarActionPerformed(java.awt.event.ActionEvent evt) {                                            
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(null, "Deseja cancelar essa venda?");
         this.dispose();
    }                                           

private void jTable1FocusLost(java.awt.event.FocusEvent evt) {                                  
// TODO add your handling code here:
}                                 

private void jt_nomeActionPerformed(java.awt.event.ActionEvent evt) {                                        

}                                       

private void jt_codigoActionPerformed(java.awt.event.ActionEvent evt) {                                          
// TODO add your handling code here:
}                                         

    private void jb_okActionPerformed(java.awt.event.ActionEvent evt) {                                      
           
        
        try {
            informacaoPadrao();
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(ControlePedido.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(ControlePedido.class.getName()).log(Level.SEVERE, null, ex);
        }

        insereDadosTabela(ativComp,linha);
       
    }                                     

    private void jb_okFocusLost(java.awt.event.FocusEvent evt) {                                
//        try {
//            // TODO add your handling code here:
//                    
//
//            conexao = ConectaBanco.getConexao();
//            Produto produto = new Produto();
//
//            String sql="select * from produto where nome='"+jt_nome.getText()+"'";
//
//
//            PreparedStatement pstmt = conexao.prepareStatement(sql);
//            ResultSet rs= pstmt.executeQuery();
//
//            informacaoPadrao();
//        } catch (ClassNotFoundException ex) {
//            Logger.getLogger(ControlePedido.class.getName()).log(Level.SEVERE, null, ex);
//        } catch (SQLException ex) {
//            Logger.getLogger(ControlePedido.class.getName()).log(Level.SEVERE, null, ex);
//        }
//        
//              insereDadosTabela(ativComp,linha);
              //jTable1.(ativComp);
            // jt_preco.setText(String.valueOf(produto.calcularPreco(produto.getPrecoCusto())));
    }                               

    private void jb_confirmarActionPerformed(java.awt.event.ActionEvent evt) {                                             
        // TODO add your handling code here:
        ControlePagamento cp2 = new ControlePagamento();
        cp2.setVisible(true);
    }                                            

    private void jTable1AncestorAdded(javax.swing.event.AncestorEvent evt) {                                      
        
    }                                     

    private void jTable1KeyPressed(java.awt.event.KeyEvent evt) {                                   
        int col = 5;
        total = 0;
        for (int i = 0; i < linha; i++) {
             double x = Integer.parseInt(jTable1.getValueAt(i, 2).toString()) * Double.parseDouble(jTable1.getValueAt(i, 3).toString());
             jTable1.setValueAt(String.valueOf(x),i, 4);
             total = total + x; 
        }
        jt_total.setText(String.valueOf(total));
    }                                  


    /**
     * @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(ControlePedido.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ControlePedido.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ControlePedido.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ControlePedido.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() {
                try {
                    new ControlePedido().setVisible(true);
                } catch (SQLException ex) {
                    Logger.getLogger(ControlePedido.class.getName()).log(Level.SEVERE, null, ex);
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(ControlePedido.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    private void insereDadosTabela(String[] x, int i ) {

        int col = jTable1.getColumnCount();

        for (int j = 0; j < col; j++) {
            jTable1.setValueAt(x[j], i, j);
        }
        linha++;
    }
    

    private void informacaoPadrao() throws ClassNotFoundException, SQLException{

        String sql = "select * from produto where nome='" + jt_nome.getText() + "'";

        conexao = ConectaBanco.getConexao();
        PreparedStatement pstmt = conexao.prepareStatement(sql);
            
        ResultSet rs = pstmt.executeQuery();
        
        String coluna1, coluna2;
        int coluna3;
        double coluna4,coluna5 = 0;
        
        try{

            while (rs.next()) {
                coluna1 = rs.getString("codigo");             
                coluna2 = rs.getString("nome");
                coluna3 = rs.getInt("qtd");
                coluna4 = rs.getDouble("preco");
                coluna5 = (coluna3*coluna4);// SEM PARENTESES

                ativComp [0] = coluna1;
                ativComp [1] = coluna2;
                ativComp [2] = String.valueOf(coluna3);
                ativComp [3] = String.valueOf(coluna4);
                ativComp [4] = String.valueOf(coluna5);

            }
            rs.close();
        
        }
        catch (SQLException ex) {
            System.out.println("Problema na conexao com a fonte de dados");
        }

        jt_total.setText(String.valueOf(total(coluna5)));
    }
    
    private double total(double x){
        total = total + x;
        return total;
    }
    
    public void salvarDados(){
       String sql="insert into pedido(codigo,nome, qtd, preco, Total) values(?,?,?,?,?)";
         
       try{
          PreparedStatement pstmt = conexao.prepareStatement(sql);
          
          pstmt.setString(1,ativComp[0]);
          pstmt.setString(2,ativComp[1]);
          pstmt.setString(3,ativComp[2]);
          pstmt.setString(4,ativComp[3]);
          pstmt.setString(5,ativComp[4]);
          
         
          pstmt.executeUpdate(sql);
   
          pstmt.close();
       }
       catch(Exception e){
           
       }
       System.out.println("" + ativComp[0]);
       System.out.println("" + ativComp[1]);
       System.out.println("" + ativComp[2]);
       System.out.println("" + ativComp[3]);
       System.out.println("" + ativComp[4]);
       
  }
    // Variables declaration - do not modify                     
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JButton jb_cancelar;
    private javax.swing.JButton jb_confirmar;
    private javax.swing.JButton jb_ok;
    private javax.swing.JButton jb_salvar;
    private javax.swing.JTextField jt_codigo;
    private javax.swing.JTextField jt_data;
    private javax.swing.JTextField jt_nome;
    private javax.swing.JTextField jt_total;
    // End of variables declaration                   
}

//CLASSE PEDIDO 
package Pedido; 
import java.util.Date; 

public class Pedido { 
private int codigo; 
private double valorTotal; 
private Date data; 
public Date getData() { 
return data; 
} 
public void setData(Date data) { 
this.data = data; 
} 

public int getCodigo() { 
return codigo; 
} 

public void setCodigo(int codigo) { 
this.codigo = codigo; 
} 
public double getValorTotal() { 
return valorTotal; 
} 
public void setValorTotal(double valorTotal) { 
this.valorTotal = valorTotal; 
} 

public double calcularTotal(double valorTotal){ 
double total=0; 

total= total + valorTotal; 
return (total); 




} 
} 
//CLASSE PEDIDODAO 
/* 
* To change this template, choose Tools | Templates 
* and open the template in the editor. 
*/ 
package Pedido; 
import java.sql.*; 
import java.util.ArrayList; 
import javax.swing.JOptionPane; 
import sgc.ConectaBanco; 
import java.sql.Connection; 


public class PedidoDao extends Pedido { 
private Date parameterIndex; 

public void realizar(Pedido pedido) throws ClassNotFoundException, SQLException{ 


Connection conexao = ConectaBanco.getConexao(); 

String sql="insert into pedido(codigo,data,valorTotal) values(?,?,?)"; 

PreparedStatement pstmt = conexao.prepareStatement(sql); 
pstmt.setInt(1,pedido.getCodigo()); 
pstmt.setDate(2,parameterIndex, null); 
pstmt.setDouble(3,pedido.getValorTotal()); 


pstmt.execute(); 

pstmt.close(); 
System.out.println("Pedido realizado com sucesso !!!"); 
} 

} 

//Agradeço desde já
I

Java_Terminator:
Olá, tu colocou errado a tag de CODE. faz assim:

[*code]
Codigo aqui dentro.
[/*code]

Só remove os asteriscos… :smiley:

Ok valew agora entendi …
Agora será que pode me ajudar? :roll:

Rodrigo_Sasaki

Agora que seu código está legível, você pode explicar melhor o seu problema?

fale o que você está tentando fazer, o que devia acontecer, e o que está acontecendo atualmente, se são lançadas exceções, diga quais e poste o stackTrace, quanto mais informação relevante melhor.

I

Então está tudo funcionando fora a data e a jtable …
eu preciso salvar a jtable no banco de dados para poder depois fazer rellatorio de vendas …
voce me ajudando a salvar a jtable no banco já está otimo :lol:

Rodrigo_Sasaki

isa-jessica:
Então está tudo funcionando fora a data e a jtable …
eu preciso salvar a jtable no banco de dados para poder depois fazer rellatorio de vendas …
voce me ajudando a salvar a jtable no banco já está otimo :lol:

Peraí que agora fiquei confuso… você quer salvar a JTable? mas isso não é um componente?
Ou você quer salvar os dados da JTable, eles ficam em alguma lista de algum tipo?

I

A sim …
Estão a data e a jtable não está salvando no banco de dados …
e preciso que salvem pois logo depois preciso fazer relatorio de vendas …
está tudo bem simples é um tcc que preciso apresentar semana que vem e só falta isso …
não faço ideia pq não está salvando …
será que pode me ajudar :roll:

Rodrigo_Sasaki

Ta, você quer salvar uma lista de objetos então, né? é isso? uma Lista de pedidos no caso? List<Pedido> pedidos; algo assim ?

I

digaoneves:
isa-jessica:
Então está tudo funcionando fora a data e a jtable …
eu preciso salvar a jtable no banco de dados para poder depois fazer rellatorio de vendas …
voce me ajudando a salvar a jtable no banco já está otimo :lol:

Peraí que agora fiquei confuso… você quer salvar a JTable? mas isso não é um componente?
Ou você quer salvar os dados da JTable, eles ficam em alguma lista de algum tipo?

sim os dados da jtable fica em um vetor chamado ativcomp está tudo na metodo salvarDados que fica no Jframe controlePedido só que acho que falta alguma coisa
pois deste modo que fiz não está salvando

Rodrigo_Sasaki

cada índice do seu array é um dos dados do pedido, ou cada índice é um pedido ?

I

sim cada indice do meu vetor é um dos dados do pedido
o primeiro é um select feito no produto para o codigo do produto, o segundo para o nome e terceiro para a quantidade e o quarto para o preço, o ultimo é um metodo chamado valor total que faz a qtd X o preço …
ai preciso salvar para depois fazer os relatorios dos pedidos …

Rodrigo_Sasaki

ta, e por que não está gravando? é lançada alguma exceção ou algo do tipo? seu método chega a ser executado ?

I

não ele copila tudo certinho mais no banco não está salvando …
e não faço ideia porque …

I

Eai pessoal vamos lá por favor alguem pode me ajudar pois tenho que apresentar meu tcc e não estou conseguindo

I

Olá desculpe o encomodo mais, se voce nao entendeu meu codigo … sera que voce nao teria um metodo para salvar jtable seu para que eu possa dar uma olhada e avaliar perante ao meu …

Rodrigo_Sasaki

Tente debugar o seu método salvarDados(), verifique se ele passa por todos os pontos certinho, porque você está dando um catch em Exception sem fazer nada, então ta engolindo qualquer exceção que estiver sendo lançada. Eu creio que algo ali está dando errado.

I

Assim valeu vou tentar tirar o try catch pois debugar eu já debuguei …

Rodrigo_Sasaki

é, tente tirar o try/catch e veja o que acontece.

você debugou e ele executou normalmente? não pulou para o bloco catch?

I

Não foi possível enviar o ponto de interupção lineBreakPoint não a local executavel.

Tentei debugar é deu esse erro.

Você tem algum outro método para salvar a jtable?

Rodrigo_Sasaki
Não tem segredo.
public static void insert(Produto produto){
	Connection con = getConnection();
		
	String insertString = "insert into Produtos values(543, 'Suco', 6323)";
	
	try {
		stmt = con.createStatement();
	   	stmt.executeUpdate(insertString1);
	
		stmt.close();
		con.close();
	
	} catch(SQLException ex) {
		System.err.println("Erro ao gravar: " + ex.getMessage());
	}

}
Se você tiver uma conexão aberta, você consegue persistir normalmente, mas o que eu suspeito é que algo não está dando certo quando você abre a conexão.

você chegou a tirar o bloco try/catch e executar tudo normalmente, pra ver se é lançada alguma exceção?

I

Boa tarde pessoal quero agradecer mais já consegui salvar mais agora tenho um outro probleminha é que minha jtable o campo quantidade dela vem de um select que dou no banco, e é editavel o valor da qtd para que possa colocar a qtd desejada mais qndo eu coloco a quantidade ela salva a que tem no banco não a que ponho …
queria saber como faço para salvar o valor que coloco

Criado 18 de maio de 2012
Ultima resposta 9 de jun. de 2012
Respostas 23
Participantes 4