Erro ao cadastrar!

9 respostas
M

urgente!!!
estou com um erro ao cadastrar!
estah dizendo q é uma string vazia, mas jah conferi meu codigo todo e naum consigo achar!!
ve se vcs conseguem me ajudar aii!!
obrigado!!

/*
 * FormDevolucoes.java
 *
 * Created on 28 de Fevereiro de 2007, 16:01
 */





/**
 *
 * @author  Aluno-04
 */
import java.text.ParseException;
import java.util.List;
import javax.swing.*;

//import para o formato da data
import javax.swing.text.MaskFormatter;
        
public class FormDevolucoes extends javax.swing.JFrame {
  
    /** Creates new form FormDevolucoes */
    public FormDevolucoes() throws ParseException {
        initComponents();
        
        //criando formato o campo data
        MaskFormatter formatadata= new MaskFormatter("####-##-##");
        formatadata.install(formatData);
        
        
        //instanciando mercadoriasdao
        MercadoriasDAO daome= new MercadoriasDAO();
        //criando um list que vai receber toda a lista de mercadorias da tabela
        List<Mercadorias> listamer=daome.listaMercadorias();
        //criando um iterator
        //percorrendo a classe mercadorias
        for(Mercadorias u: listamer){
            combmercadoria.addItem(u);
        }
    
    
    //ItensPedidoCompraDAO itens= new ItensPedidoCompraDAO();
   // List <ItensPedidoCompra> listaitens=itens.populaMercadoria();
   // for(ItensPedidoCompra i:listaitens){
     //   comboitem.addItem(i);
   // }
    
    
    
    }
    
    
    
    /** 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.
     */
    // <editor-fold defaultstate="collapsed" desc=" Código Gerado ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jLabel1 = new javax.swing.JLabel();
        devolucao = new javax.swing.JLabel();
        item = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txtdevolucao = new javax.swing.JTextField();
        btnCadastrar = new javax.swing.JButton();
        btnConsultar = new javax.swing.JButton();
        btnAlterar = new javax.swing.JButton();
        btnExcluir = new javax.swing.JButton();
        quantidade = new javax.swing.JLabel();
        txtquantidade = new javax.swing.JTextField();
        btnSair = new javax.swing.JButton();
        combmercadoria = new javax.swing.JComboBox();
        combpedido = new javax.swing.JComboBox();
        comboitem = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        btnLimpar = new javax.swing.JButton();
        formatData = new javax.swing.JFormattedTextField();
        CodItem = new javax.swing.JLabel();
        CodMercadoria = new javax.swing.JLabel();
        CodPedido = new javax.swing.JLabel();
        txtCodItem = new javax.swing.JTextField();
        txtCodMercadoria = new javax.swing.JTextField();
        txtCodPedido = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel1.setText("FORMUL\u00c1RIO DE DEVOLU\u00c7\u00d5ES");

        devolucao.setText("N\u00ba Devolu\u00e7\u00e3o");

        item.setText("N\u00ba Item");

        jLabel4.setText(" Mercadoria");

        jLabel5.setText("N\u00ba Pedido");

        btnCadastrar.setText("GRAVAR");
        btnCadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCadastrarActionPerformed(evt);
            }
        });

        btnConsultar.setText("CONSULTAR");
        btnConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConsultarActionPerformed(evt);
            }
        });

        btnAlterar.setText("ALTERAR");
        btnAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAlterarActionPerformed(evt);
            }
        });

        btnExcluir.setText("EXCLUIR");
        btnExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExcluirActionPerformed(evt);
            }
        });

        quantidade.setText("Quantidade");

        btnSair.setText("SAIR");
        btnSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSairActionPerformed(evt);
            }
        });

        combmercadoria.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                combmercadoriaItemStateChanged(evt);
            }
        });

        comboitem.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                comboitemItemStateChanged(evt);
            }
        });

        jLabel2.setText("Data Devolu\u00e7\u00e3o");

        btnLimpar.setText("LIMPAR");
        btnLimpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimparActionPerformed(evt);
            }
        });

        CodItem.setText("C\u00f3digo Item");

        CodMercadoria.setText("C\u00f3digo Mercadoria");

        CodPedido.setText("C\u00f3digo Pedido");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(52, 52, 52)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(btnConsultar)
                                    .addComponent(btnCadastrar, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(27, 27, 27)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addComponent(devolucao)
                                    .addGroup(layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel5))
                                    .addComponent(jLabel4)
                                    .addComponent(item))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(comboitem, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(combmercadoria, 0, 161, Short.MAX_VALUE)
                                    .addComponent(combpedido, 0, 161, Short.MAX_VALUE)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(txtdevolucao, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(formatData, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 114, Short.MAX_VALUE)))
                                .addGap(29, 29, 29)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 94, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(btnLimpar)
                                    .addComponent(btnSair))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(2, 2, 2)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(CodItem)
                                    .addComponent(quantidade)
                                    .addComponent(CodMercadoria)
                                    .addComponent(CodPedido))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtquantidade, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
                                    .addComponent(txtCodItem, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
                                    .addComponent(txtCodMercadoria, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
                                    .addComponent(txtCodPedido, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(225, 225, 225)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnExcluir)
                            .addComponent(btnAlterar))))
                .addGap(140, 140, 140))
            .addGroup(layout.createSequentialGroup()
                .addGap(157, 157, 157)
                .addComponent(jLabel1)
                .addContainerGap(191, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnAlterar, btnCadastrar, btnConsultar, btnExcluir, btnLimpar, btnSair});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addComponent(jLabel1)
                .addGap(53, 53, 53)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(formatData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(devolucao)
                    .addComponent(quantidade)
                    .addComponent(txtquantidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtdevolucao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(item)
                    .addComponent(CodItem)
                    .addComponent(txtCodItem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(comboitem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(16, 16, 16)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(combmercadoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(CodMercadoria)
                    .addComponent(txtCodMercadoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(combpedido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(CodPedido)
                    .addComponent(txtCodPedido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(52, 52, 52)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAlterar)
                    .addComponent(btnLimpar)
                    .addComponent(btnCadastrar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnSair)
                    .addComponent(btnConsultar))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btnAlterar, btnCadastrar, btnConsultar, btnExcluir, btnLimpar, btnSair});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void combmercadoriaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_combmercadoriaItemStateChanged
    Mercadorias mer= new Mercadorias();
    //casting...convertendo o conteudo pra o combobox
    mer=(Mercadorias) combmercadoria.getSelectedItem();
    //estou pegando o txtcodmercadoria e estou recebendo o codigo...
    //converto pra string pois a caixa de texto é string e o codigo é inteiro
    txtCodMercadoria.setText(Integer.toString(mer.getCod_mercadoria()));
           
    }//GEN-LAST:event_combmercadoriaItemStateChanged

    private void comboitemItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comboitemItemStateChanged
    ItensPedidoCompra itens = new ItensPedidoCompra();
   itens = (ItensPedidoCompra) comboitem.getSelectedItem();
   //utilizado se houver txtcodigo
   // txtCodItem.setText(""+itens.getItemn());
    }//GEN-LAST:event_comboitemItemStateChanged

    private void btnLimparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimparActionPerformed
limpar();
    }//GEN-LAST:event_btnLimparActionPerformed

    private void btnSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSairActionPerformed
System.exit(0);
    }//GEN-LAST:event_btnSairActionPerformed

    private void btnExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExcluirActionPerformed

        DevolucoesDAO.excluir(Integer.parseInt(txtdevolucao.getText()));
    }//GEN-LAST:event_btnExcluirActionPerformed

   
    
    private void btnAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAlterarActionPerformed
Devolucoes d= new Devolucoes();
DevolucoesDAO devolucao= new DevolucoesDAO();

//d.setDevolucao_n(Integer.parseInt(txtdevolucao.getText()));
d.setQtde(Integer.parseInt(txtquantidade.getText()));
d.setDt_devolucao(formatData.getText());
d.setItem_n(Integer.parseInt(txtCodItem.getText()));
d.setN_pedido(Integer.parseInt(txtCodPedido.getText()));
d.setCod_mercadoria(Integer.parseInt(txtCodMercadoria.getText()));
try{
    DevolucoesDAO.altera(d);
    
}catch(Exception e){
    JOptionPane.showMessageDialog(null, "Não foi possivel realizar a alteração");
    System.out.println(e.getMessage());
}

    
 
    }//GEN-LAST:event_btnAlterarActionPerformed

    private void btnConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConsultarActionPerformed
DevolucoesDAO dao= new DevolucoesDAO();
Devolucoes d= new Devolucoes();
dao.consultar(Integer.parseInt(txtdevolucao.getText()));
    }//GEN-LAST:event_btnConsultarActionPerformed

    private void btnCadastrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCadastrarActionPerformed
Devolucoes d= new Devolucoes();

  d.setDevolucao_n(Integer.parseInt(txtdevolucao.getText()));
  d.setQtde(Integer.parseInt(txtquantidade.getText()));
  d.setDt_devolucao(formatData.getText());
  d.setItem_n(Integer.parseInt(txtCodItem.getText()));
  d.setCod_mercadoria(Integer.parseInt(txtCodMercadoria.getText()));
  
      
        try{
           // DevolucoesDAO.cadastra(d);
            DevolucoesDAO.incluir(d);
       
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Erro no cadastro");
            System.out.println(e.getMessage());
        }
                                           
    
    }//GEN-LAST:event_btnCadastrarActionPerformed
    
    
  
              
    
    
    public void limpar(){
      formatData.setText("");
       txtdevolucao.setText("");
       txtquantidade.setText("");
       txtCodMercadoria.setText("");
       txtCodItem.setText("");
       txtCodPedido.setText("");
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new FormDevolucoes().setVisible(true);
                } catch (ParseException ex) {
                    ex.printStackTrace();
                }
            }
            });
        
    }

    
    // Declaração de variáveis - não modifique//GEN-BEGIN:variables
    private javax.swing.JLabel CodItem;
    private javax.swing.JLabel CodMercadoria;
    private javax.swing.JLabel CodPedido;
    private javax.swing.JButton btnAlterar;
    private javax.swing.JButton btnCadastrar;
    private javax.swing.JButton btnConsultar;
    private javax.swing.JButton btnExcluir;
    private javax.swing.JButton btnLimpar;
    private javax.swing.JButton btnSair;
    private javax.swing.JComboBox combmercadoria;
    private javax.swing.JComboBox comboitem;
    private javax.swing.JComboBox combpedido;
    private javax.swing.JLabel devolucao;
    private javax.swing.JFormattedTextField formatData;
    private javax.swing.JLabel item;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel quantidade;
    private javax.swing.JTextField txtCodItem;
    private javax.swing.JTextField txtCodMercadoria;
    private javax.swing.JTextField txtCodPedido;
    private javax.swing.JTextField txtdevolucao;
    private javax.swing.JTextField txtquantidade;
    // Fim da declaração de variáveis//GEN-END:variables
    
}
/*
 * DevolucoesDAO.java
 *
 * Created on 28 de Fevereiro de 2007, 16:45
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.*;


/**
 *
 * @author Aluno-04
 */
public class DevolucoesDAO {
    
    Devolucoes d= new Devolucoes();
    public static PreparedStatement stmt;
    public static String sql;
    public static ResultSet res=null;
    
    
   public static void incluir(Devolucoes d) {
     
        //conectando ao banco
        ConnectionFactory.conecta();
        //inserindo dados na tabela
        sql="INSERT into devolucoes (item_n, cod_mercadoria, n_pedido, dt_devolucao, qtde)"+ "values(?,?,?,?,?)";
        try{     
//busco as informações atraves do sql
         stmt=ConnectionFactory.con.prepareStatement(sql);
                 
                 stmt.setInt(1, d.getItem_n());
                 stmt.setInt(2, d.getCod_mercadoria());
                 stmt.setInt(3, d.getN_pedido());
                 stmt.setString(4, d.getDt_devolucao());
                 stmt.setInt(5, d.getQtde());
                 
        
               
                 if(stmt.executeUpdate()>0){
                     JOptionPane.showMessageDialog(null, "Dados cadastrados com sucesso");
                 }
              }catch(SQLException e){
                  JOptionPane.showMessageDialog(null, "Ocorreu um erro ao armazenar devolucão");
                  System.out.println(e.getMessage());
              }finally{
            try {
                stmt.close();
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
                  ConnectionFactory.desconecta();
              }}
    
    
    
              public Devolucoes consultar(int codigo){
                  Devolucoes d= new Devolucoes();
                  try{
                      ConnectionFactory.conecta();
                      sql= ("SELECT * from devolucoes WHERE devolucao_n=?");
                      stmt=ConnectionFactory.con.prepareStatement(sql);
                      stmt.setInt(1, codigo);
                      res=stmt.executeQuery();
                      
                      while(res.next()){
                        //  d.setDevolucao_n(res.getint(1));
                          d.setItem_n(res.getInt(1));
                          d.setCod_mercadoria(res.getInt(2));
                          d.setN_pedido(res.getInt(3));
                          d.setQtde(res.getInt(4));
                          d.setDt_devolucao(res.getString(5));
                        
                      }
                      
                      }catch(SQLException e){
                          JOptionPane.showMessageDialog(null, "Não foi possivel realizar a consulta");
                          System.out.println(e.getMessage());
                      }finally{
                          try{
                          res.close();
                          stmt.close();
                          }catch(SQLException ex){
                              ex.printStackTrace();
                          }
                          ConnectionFactory.desconecta();
                          return (d);
                                                  
                      }
              }
              
                      //set le
                      //get grava
                      public static void altera(Devolucoes d){
                          try{
                              ConnectionFactory.conecta();
                              sql="UPDATE devolucoes set devolucao_n=?, item_n=?, cod_mercadoria=?, n_pedido=?, dt_devolucao, qtde WHERE devolucao_n='" + d.getDevolucao_n()+ "'";
                              stmt=ConnectionFactory.con.prepareStatement(sql);
                              stmt.setInt(1, d.getDevolucao_n());
                              stmt.setInt(2, d.getItem_n());
                              stmt.setInt(3, d.getCod_mercadoria());
                              stmt.setInt(4, d.getN_pedido());
                              stmt.setInt(5, d.getQtde());
                              stmt.setString(6, d.getDt_devolucao());
                              
                              //executa a alteração
                              stmt.executeUpdate();
                              JOptionPane.showMessageDialog(null, "Alteração realizada com sucesso!");
                          }catch (SQLException e){
                              JOptionPane.showMessageDialog(null, "Não foi possivel realizar a alteração");
                              System.out.println(e.getMessage());
                          }finally{
            try {
                
                stmt.close();
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
                              ConnectionFactory.desconecta();                                          
                                                     }
                      }
                      
                      
                      
                      public static void excluir(int codigo){
                          try{
                              ConnectionFactory.conecta();
                              sql= "DELETE from devolucoes WHERE devolucao_n=?";
                              stmt=ConnectionFactory.con.prepareStatement(sql);
                              stmt.setInt(1, codigo);
                              stmt.executeUpdate();
                              JOptionPane.showMessageDialog(null,  "Cadastro excluido com sucesso");
                          }catch (SQLException e){
                              JOptionPane.showMessageDialog(null, "Não foi possivel excluir o fornecedor");
                              System.out.println(e.getMessage());
                          }
                                      
                          }
                          
                      }

9 Respostas

nbluis

Especifique onde dá o erro dentro do codigo.

Romeo

é bom, pq acho que ninguém tem paciência pra verificar mais de 200 linhas de código…

M
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
M

desculpa aii achei q tinha eviado o erro junto
ta aii!!

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
M

o erro aii

Exception in thread “AWT-EventQueue-0” java.lang.NumberFormatException: For input string: “”

java_Regi

aconteceu cmgo esses dias ai isso,
eu montei minha tela de cadastro.
montei o codigo.
e blza,

na hora de passar as informações no textfield eu não passei nada em tal textfield, deixei um em branco.
ai me lanço esse erro ai,

tenta passar toddos os parametros certinho.

M

ah blz!!
so q eu naum preencho todos os campos pq o codigo é auto incremento
e qdo faço isso aparece esse erro:

Cannot add or update a child row: a foreign key constraint fails (java02/devolucoes, CONSTRAINT devolucoes_ibfk_2 FOREIGN KEY (cod_mercadoria) REFERENCES itens_pedido (cod_mercadoria) ON DELETE NO ACTION ON UPDATE NO ACTION)

Romeo

Deve ser o que o java_Regi falou
E quando passar o erro fala a linha também… pq esse tipo de erro pode acontecer em qualquer lugar

M

naum tem linha errada (acredito!!), pq o erro q dá qd eu preencho todos os campos, inclusive o q é auto incremento é esse:

Cannot add or update a child row: a foreign key constraint fails (java02/devolucoes, CONSTRAINT devolucoes_ibfk_2 FOREIGN KEY (cod_mercadoria) REFERENCES itens_pedido (cod_mercadoria) ON DELETE NO ACTION ON UPDATE NO ACTION)

Criado 2 de março de 2007
Ultima resposta 2 de mar. de 2007
Respostas 9
Participantes 4