Oii … nosso programa do TCC não está cadastrando, e não está dando nenhum erro na hora que compila.!
Se alguem puder ajudar, agradecemos.!
Pryscila, Jessica, Mirian
[code]import java.sql.;
import javax.swing.;
import java.awt.;
import java.awt.event.;
class ProjetoCad extends JFrame implements ActionListener
{
JLabel L1,L2,L3,L4,L5,L6,L7,L8;
JButton b1,b2,b3,b4,b5;
static JTextField tfcod,tfnome,tfcep,tfrg,tftel,tflocal,tfemp;
JPanel p1 = new JPanel();
ResultSet rs;
Statement MeuState;
public static void main(String args[])
{
JFrame Janela = new ProjetoCad();
Janela.show();
WindowListener x = new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
};
Janela.addWindowListener(x);
}
ProjetoCad()
{
p1.setLayout(new FlowLayout(FlowLayout.LEFT));
L1 = new JLabel("Código: ");
L2 = new JLabel("Nome: ");
L3 = new JLabel("CEP: ");
L4 = new JLabel("RG: ");
L5 = new JLabel("Telefone: ");
L6 = new JLabel("Local: ");
L7= new JLabel("Empresa: “);
L8 = new JLabel(” “);
for (int i=0;i<60;i++)
L8.setText(L8.getText()+” ");
tfcod = new JTextField(10);
tfcod.addActionListener(this);
tfnome = new JTextField(35);
tfnome.addActionListener(this);
tfcep = new JTextField(10);
tfcep.addActionListener(this);
tfrg = new JTextField(15);
tfrg.addActionListener(this);
tftel = new JTextField(8);
tftel.addActionListener(this);
tflocal = new JTextField(10);
tflocal.addActionListener(this);
tfemp = new JTextField(10);
tfemp.addActionListener(this);
b1=new JButton(“Inserir”);
b2=new JButton(“Atualizar”);
b3=new JButton(“Excluir”);
b4=new JButton(“Localizar”);
b5=new JButton(“Novo”);
b1.setBackground(new Color(200,100,150));
b2.setBackground(new Color(200,100,150));
b3.setBackground(new Color(200,100,150));
b4.setBackground(new Color(200,100,150));
b5.setBackground(new Color(200,100,150));
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
p1.add(L1); p1.add(tfcod); p1.add(L2); p1.add(tfnome);
p1.add(L3); p1.add(tfcep); p1.add(L4); p1.add(tfrg);
p1.add(L5); p1.add(tftel); p1.add(L6); p1.add(tflocal);p1.add(L7); p1.add(tfemp);p1.add(L8);
p1.add(b1); p1.add(b2); p1.add(b3);p1.add(b4);p1.add(b5);
getContentPane().add(p1);
setTitle(“Cadastramento de clientes”);
setSize(770,130);
setResizable(false);
String url = “jdbc:odbc:MeuBanco2”;
try
{
Class.forName( “sun.jdbc.odbc.JdbcOdbcDriver” );
Connection Conexao = DriverManager.getConnection(url);
MeuState = Conexao.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs = MeuState.executeQuery(“SELECT * FROM Cliente”);
rs.first();
atualizaCampos();
}
catch(ClassNotFoundException ex)
{
System.out.println(“Driver JDBC-ODBC não encontrado!”);
}
catch(SQLException ex)
{
System.out.println(“Problemas na conexao com a fonte de dados”);
}
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==b5)
{
limpaCampos();
return;
}
if (e.getSource()==b1)
//inserir
{
try
{
String SQL = “INSERT INTO Cliente(cod,nome,cep,rg,tel,local,emp) Values (’”+tfcod.getText()+"’,’"+tfnome.getText()+"’,’"+tfcep.getText()+"’,’"+tfrg.getText()+"’,’"+tftel.getText()+"’,’"+tflocal.getText()+"’,’"+tfemp.getText()+"’,’"+"’)";
MeuState.executeUpdate(SQL);
JOptionPane.showMessageDialog(null,“Cliente cadastrado com sucesso.”);
limpaCampos();
}
catch(SQLException ex)
{
if (ex.getMessage().equals(“General error”))
JOptionPane.showMessageDialog(null,“Cliente já cadastrado”);
else
JOptionPane.showMessageDialog(null,“Erro ao cadastrar”);
}
}
// ------------------ Final da Inclusão -------------------
if (e.getSource()==b2)
//Atualizar
{
try
{
String SQL = "UPDATE Cliente SET "+"cod='"+tfcod.getText()+"',"+"nome='"+tfnome.getText()+"',"+"cep='"+tfcep.getText()+"',"+"rg='"+tfrg.getText()+"',"+"tel='"+tftel.getText()+"',"+"local='"+tflocal.getText()+"',"+"emp='"+tfemp.getText()+"' WHERE cod = '"+tfcod.getText()+"'";
int r = MeuState.executeUpdate(SQL);
if (r==1)
JOptionPane.showMessageDialog(null,"Atualização realizada com sucesso.");
else
JOptionPane.showMessageDialog(null,"Esse cliente ainda não está cadastrado.");
}
catch(SQLException ex) { }
}
// ------------------ Final da Atualização -------------------
if (e.getSource()==b3)
// Excluir
{
try
{
String SQL = “SELECT cod, nome FROM Cliente Where cod = '”+tfcod.getText()+"’";
rs = MeuState.executeQuery(SQL);
String cod = “”;
try
{
rs.next();
cod = “Deletar o cadastro do cliente: “+rs.getString(“cod”);
}
catch(SQLException ex1)
{
JOptionPane.showMessageDialog(null,“Cliente nao cadastrado!”);
return;
}
int n = JOptionPane.showConfirmDialog(null,cod,” “,JOptionPane.YES_NO_OPTION);
if (n==JOptionPane.YES_OPTION)
{
SQL = “DELETE FROM Cliente Where cod = '”+tfcod.getText()+”’”;
int r = MeuState.executeUpdate(SQL);
if (r==1)
JOptionPane.showMessageDialog(null,“Exclusão realizada com sucesso”);
else
JOptionPane.showMessageDialog(null,“Não foi possível excluir o cadastro do cliente”);
}
else
return;
}
catch(SQLException ex){ }
limpaCampos();
}
// ------------------ Final da Exclusão -------------------
if (e.getSource()==b4 || e.getSource()==tfcod)
{
try
{
String SQL = “SELECT * FROM Cliente Where cod = '”+tfcod.getText()+"’";
rs = MeuState.executeQuery(SQL);
rs.next();
tfcod.setText(rs.getString(“cod”));
tfnome.setText(rs.getString(“nome”));
tfcep.setText(rs.getString(“cep”));
tfrg.setText(rs.getString(“rg”));
tftel.setText(rs.getString(“tel”));
tflocal.setText(rs.getString(“local”));
tfemp.setText(rs.getString(“emp”));
}
catch(SQLException ex)
{
JOptionPane.showMessageDialog(null,“Cliente não encontrado.”);
return;
}
}
// ------------------ Final da Localização -------------------
}
public static void limpaCampos()
{
tfcod.setText("");
tfnome.setText("");
tfcep.setText("");
tfrg.setText("");
tftel.setText("");
tflocal.setText("");
tfemp.setText("");
}
public void atualizaCampos()
{
try
{
tfcod.setText(rs.getString(“cod”));
tfnome.setText(rs.getString(“nome”));
tfcep.setText(rs.getString(“cep”));
tfrg.setText(rs.getString(“rg”));
tftel.setText(rs.getString(“tel”));
tflocal.setText(rs.getString(“local”));
tfemp.setText(rs.getString(“emp”));
}
catch(SQLException ex)
{ }
}
}[/code]
