ActionPerfomed e MySql

2 respostas
S

Galera, consegui conectar meu banco, consegui inserir os dados q escrevo nos campos, mas quando vou repetir a inserção de um novo documento com os mesmos campos e no mesmo tempo de execução do programa eu não consigo inserir, dá o seguinte erro:

Exception in thread AWT-EventQueue-0 java.lang.NullPointerException

at unir.JanelaCadastro.actionPerformed(JanelaCadastro.java:333)

at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)

at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.setPressed(Unknown Source)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)

at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)

at java.awt.Component.processMouseEvent(Unknown Source)

at javax.swing.JComponent.processMouseEvent(Unknown Source)

at java.awt.Component.processEvent(Unknown Source)

at java.awt.Container.processEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Window.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

O q será?..

Valeu Comunidade!!!

2 Respostas

J

Oi

Skrotinho, isso aí não tem a ver com o MySQL mais, é um erro que está acontecendo na lógica que tu fez pra fazer esta inserção, estas deixando alguma coisa nula… Se puder postar uma parte do código, já ajuda…

T+

S

Meu fonte está asssim no ActionPerfomed:

if(miSalvar==event.getSource()||JBsalvar==event.getSource())
{ JOptionPane.showMessageDialog(null,“Salvar”);

try {	ConexaoBD bd=new ConexaoBD();//estou instanciando

stmt=(Statement) ConexaoBD.getCon().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY );

String query = "INSERT INTO aluno(cpf_aluno,nome_aluno,dt_nasc)

VALUES (’"+Fcpf.getText().trim()+"’,’"+ Fnome.getText().trim() + “’,’” + Fdt_nasc.getText().trim() + “’)”;

int r = stmt.executeUpdate( query );
	
  if(r == 1)
System.out.println("Sucesso na Insersão");
  else
JOptionPane.showMessageDialog(null," Falha na Insersão ");
				
   stmt.close();
   ConexaoBD.closeConnection();

}catch ( SQLException sqlex ) {

if(sqlex.getMessage().equals("General error"))
JOptionPane.showMessageDialog(null,Aluno  Cadastrado!!!);

}

}//FIM BOTÃO INSERIR
Criado 19 de fevereiro de 2005
Ultima resposta 19 de fev. de 2005
Respostas 2
Participantes 2