eu tenho esse codigo e nao ta querendo funcionar alguem me ajuda??
import java.awt.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import java.awt.event.*;
import java.sql.PreparedStatement.*;
public class Menu extends JFrame implements ActionListener {
Cliente cliente = new Cliente();
MeuJTextField mjtfCodigo = new MeuJTextField(20,true);
MeuJTextField mjtfNome = new MeuJTextField(20,true);
MeuJTextField mjtfEndereco = new MeuJTextField(20,false);
MeuJTextField mjtfCPF = new MeuJTextField(10,true);
JButton jbOK = new JButton("OK");
JButton jbVerifica = new JButton("Verificar");
Conexao conexao = new Conexao();
public static void main (String args[]) {
Menu menu = new Menu();
}
public Menu() {
getContentPane().setLayout(new GridLayout(5,4));
getContentPane().add(new JLabel("Codigo:"));
getContentPane().add(mjtfCodigo);
getContentPane().add(new JLabel("Nome:"));
getContentPane().add(mjtfNome);
getContentPane().add(new JLabel("Endereco:"));
getContentPane().add(mjtfEndereco);
getContentPane().add(new JLabel("CPF"));
getContentPane().add(mjtfCPF);
getContentPane().add(jbOK);
getContentPane().add(jbVerifica);
jbOK.addActionListener(this);
jbVerifica.addActionListener(this);
// getContentPane().add(jbCancela);
setSize(400,250);
cliente.getCodigo(mjtfCodigo.getText());
cliente.getNome(this.mjtfNome.getText());
cliente.getCPF(mjtfCPF.getText());
cliente.getEndereco(mjtfEndereco));
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == jbOK) {
cliente.inserir();
}
}
class MeuJTextField extends JTextField implements FocusListener {
private boolean obrigatorio = false;
public MeuJTextField(int tamanho, boolean obrigatorio) {
super(tamanho);
this.obrigatorio = obrigatorio;
if (obrigatorio)
setBackground(Color.yellow);
else
setBackground(Color.white);
addFocusListener(this);
}
public void focusGained(FocusEvent e) {
setBackground(Color.orange);
}
public void focusLost(FocusEvent e) {
if (obrigatorio)
setBackground(Color.yellow);
else
setBackground(Color.white);
}
}
class MeuPainelComboBox extends JPanel {
private JComboBox jcb = new JComboBox();
public MeuPainelComboBox() {
super();
setLayout(new GridLayout(1,2));
add(jcb);
}
}
}
import java.sql.Connection;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
/**
*
* @author luzaum
*/
public class Conexao {
private static Connection con = null;
public static Connection abrirConexao(){
if (con == null) {
try { Class.forName("org.firebirdsql.jdbc.FBDriver");
con = DriverManager.getConnection("jdbc:firebirdsql:localhost:C:\\TESTE.FDB", "SYSDBA", "masterkey");
} catch (Exception ex) {
Logger.getLogger(Conexao.class.getName()).log(Level.SEVERE, null, ex);
JOptionPane.showMessageDialog(null,"Conexão não estabelecida ","Vifique o sistema",JOptionPane.ERROR_MESSAGE);
}
}
return con;
}
public void fecharConexao(){
try { con.close();
con = null;
} catch (SQLException ex) {
Logger.getLogger(Conexao.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.sql.Connection;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import java.sql.PreparedStatement;
/**
*
* @author alunos
*/
public class Cliente {
private int codigo;
private String nome;
private String endereco;
private String cpf;
public void setCodigo(int codigo) {
this.codigo = codigo;
}
public int getCodigo() {
return codigo;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getNome() {
return nome;
}
public void setEndereco(String endereco) {
this.endereco = endereco;
}
public String getEndereco() {
return endereco;
}
public void setCPF(String cpf) {
this.cpf = cpf;
}
public String getCPF() {
return cpf;
}
public void inserir() {
try { Connection con = Conexao.abrirConexao();
PreparedStatement ps = con.prepareStatement("insert into cliente values(?,?,?,?)");
ps.setInt(1, codigo);
ps.setString(2, nome);
ps.setString(3,endereco);
ps.setString(4,cpf);
ps.executeUpdate();
JOptionPane.showMessageDialog(null,"Query executada com sucesso");
}
catch (SQLException e) {
e.printStackTrace();
}
}
}
ele so incerta null no banco de dados =/
magoei