Salvar Dados no Firebird no evento do Jbutton

0 respostas
helder.emiliano
Pessoal , boa tarde , não estou conseguindo adicionar os itens do meu jframe a uma tabela do banco de dados(firebird2.5)porém está conectando vom o banco, mas não insere os dados na tabela. Segue os códigos da tabela, da conexão e do botão inserir: Tabela: CREATE TABLE CAD_MECANICO ( COD_MECANICO integer not null primary key, NOME_MECANICO varchar(100) not null, FONE_MECANICO varchar(13), CPF_MECANICO char(11) not null); Conexão com Banco:
package utilitarios;
import java.sql.*;
import javax.swing.*;


public class ConexaoBanco{

final private String Driver = "org.firebirdsql.jdbc.FBDriver";
final private String url = "jdbc:firebirdsql://localhost:3050/C:\Temp\Banco\CLIENTE.FDB";
final private String Usuario = "SYSDBA";
final private String Senha = "masterkey";
private Connection ConexaoBanco;
public Statement statement;
public ResultSet resultset;
  public boolean conecta()
       {
            boolean result = true;
            try
            {
                Class.forName(Driver);
                ConexaoBanco = DriverManager.getConnection(url, Usuario, Senha);
                JOptionPane.showMessageDialog(null,"conectou !");//vc pode descomentar para saber quando o banco fica conectado
            }
            catch(ClassNotFoundException Driver)
            {
               JOptionPane.showMessageDialog(null,"Driver não localizado: "+Driver);
               result = false;
            }
            catch(SQLException Fonte)
            {
                JOptionPane.showMessageDialog(null,"Deu erro na conexão "+
                        "com a fonte de dados: "+Fonte);
                result = false;
            }
            return result;
       }

       public void desconecta()
       {
            boolean result = true;
            try
            {
                ConexaoBanco.close();
                JOptionPane.showMessageDialog(null,"banco fechado");
            }
            catch(SQLException fecha)
            {
                JOptionPane.showMessageDialog(null,"Não foi possivel "+
                        "fechar o banco de dados: "+fecha);
                result = false;
            }

       }

    public void executeQuery(String string) {
        throw new UnsupportedOperationException("Not yet implemented");
    }


public void executeSQL(String sql) {
try {
if (ConexaoBanco == null) {
this.conecta();
}
PreparedStatement ps = ConexaoBanco.prepareStatement(sql);
resultset = ps.executeQuery();
} catch(SQLException sqlex) {
JOptionPane.showMessageDialog(null,"Não foi possível executar o comando sql, " + sqlex);
}
}

    public Statement createStatment() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

}
Botão Inserir:
private void jbInserirClienteActionPerformed(java.awt.event.ActionEvent evt) {
    try{ //tratamento de erros

int CodMec = Integer.parseInt(jtCodMecanico.getText());
String CadNome = jtNomeMecanico.getText(); //obtém nome digitado
String CadFone= jfFoneMecanico.getText() ;
String CadCPF = jfCPFMecanico.getText();
conMecanicos.statement.executeUpdate( "insert  into CAD_MECANICO (COD_MECANICO, NOME_MECANICO, FONE_MECANICO, CPF_MECANICO) values (' " +CodMec + " ',' " +CadNome + " ',' " +CadFone + " ',' " +CadCPF + " ' )  ");
JOptionPane.showMessageDialog( this, " Dados Salvos! ");conMecanicos.desconecta(); // fecha conexão com BD
} catch( SQLException e){ //trata os erros
JOptionPane.showMessageDialog(this, "Erro Cmdo SQL " +
e.getMessage() );
}    // TODO add your handling code here:
    }
e o erro: Have no FileObject for C:\Program Files (x86)\Java\jdk1.6.0_20\jre\lib\sunrsasign.jar Have no FileObject for C:\Program Files (x86)\Java\jdk1.6.0_20\jre\classes Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at Interfaces.frmCadastroMecanico.jbInserirClienteActionPerformed(frmCadastroMecanico.java:186) at Interfaces.frmCadastroMecanico.access$000(frmCadastroMecanico.java:24) at Interfaces.frmCadastroMecanico$1.actionPerformed(frmCadastroMecanico.java:79) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236) at java.awt.Component.processMouseEvent(Component.java:6263) at javax.swing.JComponent.processMouseEvent(JComponent.java:3267) at java.awt.Component.processEvent(Component.java:6028) at java.awt.Container.processEvent(Container.java:2041) at java.awt.Component.dispatchEventImpl(Component.java:4630) at java.awt.Container.dispatchEventImpl(Container.java:2099) at java.awt.Component.dispatchEvent(Component.java:4460) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168) at java.awt.Container.dispatchEventImpl(Container.java:2085) at java.awt.Window.dispatchEventImpl(Window.java:2478) at java.awt.Component.dispatchEvent(Component.java:4460) at java.awt.EventQueue.dispatchEvent(EventQueue.java:599) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161) at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Alguem pode me dar alguma dica do que está errado?
Obrigado

Criado 16 de junho de 2010
Respostas 0
Participantes 1