Boa noite. Sou estudante de sistemas de informação e sou iniciante em Java. Estou desenvolvendo uma aplicação que tem três tabelas em um banco: cliente(principal), anuncio, tipo de anuncio.
Criei um projeto em java com a seguinte estrutura de diretorios: codigo: Classes -> Cliente e Anuncio, Cliente com as classes: ConnectionFactory e Dao e visual com o painel da minha aplicação.
Criei as funções para os botões e ao mandar cadastrar os dados ocorre a seguinte mensagem de erro:
31/07/2008 00:10:40 estevam.visual.Aplicacao cadastra
SEVERE: null
java.sql.SQLException: com.mysql.driver
at estevam.banco.ConnectorFactory.getConnection(ConnectorFactory.java:34)
at estevam.banco.Dao.<init>(Dao.java:25)
at estevam.visual.Aplicacao.cadastra(Aplicacao.java:295)
at estevam.visual.Aplicacao.jButtonCadastrarActionPerformed(Aplicacao.java:268)
at estevam.visual.Aplicacao.access$200(Aplicacao.java:28)
at estevam.visual.Aplicacao$3.actionPerformed(Aplicacao.java:167)
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:6216)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at java.awt.Component.processEvent(Component.java:5981)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4583)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4413)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4556)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4220)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4150)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4413)
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)
O que pode esta acontecendo segue abaixo os codigos fontes da minha aplicação
[code]
/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package estevam.codigo;
import java.awt.event.ActionListener;
/**
*
-
@author estevam
*/
public class Anuncio {
//Declaração dos atributos da classeprivate String assuntoAnuncio;
private String categoriaAnuncio;
private String subCategoriaAnuncio;
private String descricaoCategoria;
private String descricaoAnuncio;
private String fotoAnuncio;
private String valorServico_Produto;
private String valorAnuncio;//Metodo construtor
public Anuncio(){}
public Anuncio(String descricaAnuncio, String valorServico_Produto) {
setDescricaoAnuncio(valorServico_Produto); setValorServico_produto(valorServico_Produto);
}
//Metodos de encapsulamento get e set
public void setAssuntoAnuncio(String assuntoAnuncio){
this.assuntoAnuncio = assuntoAnuncio;
}
public String getAssuntoAnuncio(){
return assuntoAnuncio;
}public void setCategoriaAnuncio(String categoriaAnuncio){
this.categoriaAnuncio =categoriaAnuncio;
}
public String getCategoriaAnuncio(){
return categoriaAnuncio;
}public void setSubCategoriaAnuncio(String subCategoriaAnuncio){
this.subCategoriaAnuncio = subCategoriaAnuncio;
}
public String getSubCategoriaAnuncio(){
return subCategoriaAnuncio;
}public void setDescricaoCategoria(String descricaoCategoria){
this.descricaoCategoria =descricaoCategoria;
}
public String getDescricaoCategoria(){
return descricaoCategoria;
}public void setDescricaoAnuncio(String descricaoAnuncio){
this.descricaoAnuncio = descricaoAnuncio;
}
public String getDescricaoAnuncio(){
return descricaoAnuncio;
}public void setFotoAnuncio(String fotoAnuncio){
this.fotoAnuncio = fotoAnuncio;
}
public String getFotoAnuncio(){
return fotoAnuncio;
}public void setValorServico_produto(String valorServico_produto){
this.valorServico_Produto = valorServico_produto;
}
public String getValorServico_produto(){
return valorServico_Produto;
}public void setValorAnuncio(String valorAnuncio){
this.valorAnuncio =valorAnuncio;
}
public String getValorAnuncio(){
return valorAnuncio;
}
}[/code]
package estevam.codigo;
public class Cliente {
//Declaracao dos atributos
private String cpf;
private String nome;
private String endereco;
private String email;
private String telefone;
//Metodo construtor
public Cliente(){
setNome(nome);
setCpf(cpf);
}
public String getCpf() {
return cpf;
}
public void setCpf(String cpf) {
this.cpf = cpf;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getEndereco() {
return endereco;
}
public void setEndereco(String endereco) {
this.endereco = endereco;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getTelefone() {
return telefone;
}
public void setTelefone(String telefone) {
this.telefone = telefone;
}
}
A minha aplicação visual tem na tela dados das tres tabelas, para efeito de testes eu so fiz o Dao com a inclusão de campos em duas tabelas cliente campo CPF e anuncio campos descricaoAnuncio, ValorServico_Produto
[code]
/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package estevam.banco;
import estevam.codigo.Anuncio;
import estevam.codigo.Cliente;
import java.sql.*;
import java.sql.PreparedStatement;
import java.sql.SQLException;
/**
*
-
@author estevam
*/
public class Dao {//
private Connection connection;//Metodo construtor da DAO
public Dao() throws SQLException{
this.connection = ConnectorFactory.getConnection();
}//Metodo para adicionar os dados no banco
public void adiciona(Anuncio adiciona, Cliente cliente) throws SQLException{//Preparando o preparement e criando a linha de inserçao ao banco //inserção ao banco tipo anuncio //PreparedStatement stmt = this.connection.prepareStatement("INSERT INTO tipoanuncio" // +"(assuntoAnuncio,subCategoriaAnuncio) VALUES (?,?)"); //Inserção ao banco anuncio PreparedStatement stmt2 = this.connection.prepareStatement("INSERT INTO anuncio" +"(descricaoAnuncio, valorServico_Produto)VALUES (?,?)"); PreparedStatement stmt3 = this.connection.prepareStatement("INSERT INTO cliente" + "(cpf) VALUES (?)"); //Setando os dados //tipo anuncio /* stmt.setString(1, adiciona.getAssuntoAnuncio()); stmt.setString(2, adiciona.getSubCategoriaAnuncio()); //Fecha a conexão. stmt.execute(); stmt.close();*/ //anuncio stmt2.setString(1, adiciona.getDescricaoAnuncio()); stmt2.setString(2, adiciona.getValorServico_produto()); stmt2.setString(3, adiciona.getValorAnuncio()); stmt2.execute(); stmt2.close(); stmt3.setString(1, cliente.getCpf()); stmt3.execute(); stmt3.close();
}
}[/code]
segue o codigo da minha Aplicação (interface visual)
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* Aplicacao.java
*
* Created on 28/07/2008, 18:36:56
*/
package estevam.visual;
import estevam.banco.Dao;
import estevam.codigo.Anuncio;
import estevam.codigo.Cliente;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
/**
*
* @author estevam
*/
public class Aplicacao extends javax.swing.JFrame {
private ComboBoxModel aModel;
/** Creates new form Aplicacao */
public Aplicacao() {
initComponents();
desabilitaCampos();
}
/** 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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanelprincipal = new javax.swing.JPanel();
jPanelDadosAnuncio = new javax.swing.JPanel();
jLabelAssunto = new javax.swing.JLabel();
jLabelCpf = new javax.swing.JLabel();
jLabelSubCategoria = new javax.swing.JLabel();
jLabelAnuncio = new javax.swing.JLabel();
jLabelFotot = new javax.swing.JLabel();
jLabelValorServico_produto = new javax.swing.JLabel();
jLabelValorAnuncio = new javax.swing.JLabel();
jComboBoxAssunto = new javax.swing.JComboBox();
jComboBoxSubCategoria = new javax.swing.JComboBox();
jScrollPane1 = new javax.swing.JScrollPane();
jTextAreaAnuncio = new javax.swing.JTextArea();
jTextFieldValorServico_produto = new javax.swing.JTextField();
jTextFieldCpf = new javax.swing.JTextField();
jPanelBotoes = new javax.swing.JPanel();
jButtonNovo = new javax.swing.JButton();
jButtonCadastrar = new javax.swing.JButton();
jButtonLimpar = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Cadastro de Anúncio");
jPanelDadosAnuncio.setBorder(javax.swing.BorderFactory.createTitledBorder("Dados Anúncio\n"));
jLabelAssunto.setText("Assunto");
jLabelCpf.setText("CPF");
jLabelSubCategoria.setText("Sub categoria");
jLabelAnuncio.setText("Anuncio");
jLabelFotot.setText("Foto");
jLabelValorServico_produto.setText("Valor serviço produto");
jLabelValorAnuncio.setText("Valor do anuncio");
jComboBoxAssunto.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Escolha um assunto", "Compra", "Venda", "Aluguel", " " }));
jComboBoxSubCategoria.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Escolha uma sub categoria", "Veiculos", "Casas", "Excursões", " " }));
jTextAreaAnuncio.setColumns(20);
jTextAreaAnuncio.setRows(5);
jScrollPane1.setViewportView(jTextAreaAnuncio);
jTextFieldValorServico_produto.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextFieldValorServico_produtoActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanelDadosAnuncioLayout = new javax.swing.GroupLayout(jPanelDadosAnuncio);
jPanelDadosAnuncio.setLayout(jPanelDadosAnuncioLayout);
jPanelDadosAnuncioLayout.setHorizontalGroup(
jPanelDadosAnuncioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanelDadosAnuncioLayout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanelDadosAnuncioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanelDadosAnuncioLayout.createSequentialGroup()
.addGroup(jPanelDadosAnuncioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabelAssunto, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabelSubCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabelAnuncio, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabelCpf, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(62, 62, 62)
.addGroup(jPanelDadosAnuncioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jComboBoxSubCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanelDadosAnuncioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jComboBoxAssunto, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jTextFieldCpf, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE))))
.addComponent(jLabelFotot, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanelDadosAnuncioLayout.createSequentialGroup()
.addComponent(jLabelValorServico_produto, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jTextFieldValorServico_produto, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLabelValorAnuncio, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(38, Short.MAX_VALUE))
);
jPanelDadosAnuncioLayout.setVerticalGroup(
jPanelDadosAnuncioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanelDadosAnuncioLayout.createSequentialGroup()
.addGap(23, 23, 23)
.addGroup(jPanelDadosAnuncioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabelCpf, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextFieldCpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanelDadosAnuncioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabelAssunto, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jComboBoxAssunto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanelDadosAnuncioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabelSubCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jComboBoxSubCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanelDadosAnuncioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabelAnuncio, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(13, 13, 13)
.addComponent(jLabelFotot)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanelDadosAnuncioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabelValorServico_produto, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextFieldValorServico_produto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(jLabelValorAnuncio, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(31, Short.MAX_VALUE))
);
jButtonNovo.setText("Novo anuncio");
jButtonNovo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonNovoActionPerformed(evt);
}
});
jButtonCadastrar.setText("Cadastrar");
jButtonCadastrar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonCadastrarActionPerformed(evt);
}
});
jButtonLimpar.setText("Limpar");
jButtonLimpar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonLimparActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanelBotoesLayout = new javax.swing.GroupLayout(jPanelBotoes);
jPanelBotoes.setLayout(jPanelBotoesLayout);
jPanelBotoesLayout.setHorizontalGroup(
jPanelBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanelBotoesLayout.createSequentialGroup()
.addContainerGap()
.addComponent(jButtonNovo)
.addGap(48, 48, 48)
.addComponent(jButtonCadastrar)
.addGap(30, 30, 30)
.addComponent(jButtonLimpar)
.addContainerGap(35, Short.MAX_VALUE))
);
jPanelBotoesLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButtonCadastrar, jButtonLimpar, jButtonNovo});
jPanelBotoesLayout.setVerticalGroup(
jPanelBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanelBotoesLayout.createSequentialGroup()
.addContainerGap(21, Short.MAX_VALUE)
.addGroup(jPanelBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButtonNovo)
.addComponent(jButtonCadastrar)
.addComponent(jButtonLimpar))
.addContainerGap())
);
javax.swing.GroupLayout jPanelprincipalLayout = new javax.swing.GroupLayout(jPanelprincipal);
jPanelprincipal.setLayout(jPanelprincipalLayout);
jPanelprincipalLayout.setHorizontalGroup(
jPanelprincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanelprincipalLayout.createSequentialGroup()
.addGap(48, 48, 48)
.addGroup(jPanelprincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jPanelBotoes, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanelDadosAnuncio, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(74, Short.MAX_VALUE))
);
jPanelprincipalLayout.setVerticalGroup(
jPanelprincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanelprincipalLayout.createSequentialGroup()
.addGap(25, 25, 25)
.addComponent(jPanelDadosAnuncio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jPanelBotoes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(32, 32, 32))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanelprincipal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanelprincipal, javax.swing.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>
private void jTextFieldValorServico_produtoActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButtonNovoActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
habilitaCampos();
}
private void jButtonLimparActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jTextFieldCpf.setText("");
jComboBoxAssunto.setSelectedItem("Escolha um assunto");
jComboBoxSubCategoria.setSelectedItem("Escolha uma sub categoria");
jTextAreaAnuncio.setText("");
jTextFieldValorServico_produto.setText("");
}
private void jButtonCadastrarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(validaCampos() == true){
cadastra();
}
}
//Metodo para validar o campo cpf
public boolean validaCampos(){
String caracteres = "0123456789";
if(!jTextFieldCpf.equals("") && !jTextFieldValorServico_produto.equals("")) {
return true;
}
else{
JOptionPane.showMessageDialog(null, "CPF campo obrigatorio. \n Favor preencher.");
return false;
}
}
//Metodo para cadastrar os dados
public void cadastra(){
try {
//Instancia da Classe Anuncio
Anuncio cadastra = new Anuncio();
cadastra.setDescricaoAnuncio(jTextAreaAnuncio.getText());
cadastra.setValorServico_produto(jTextFieldValorServico_produto.getText());
//Instancia da classe cliente
Cliente cad = new Cliente();
cad.setCpf(jTextFieldCpf.getText());
Dao db = new Dao();
db.adiciona(cadastra, cad);
JOptionPane.showMessageDialog(null, "Anuncio cadastrado com sucesso.");
} catch (SQLException ex) {
Logger.getLogger(Aplicacao.class.getName()).log(Level.SEVERE, null, ex);
JOptionPane.showMessageDialog(null, "Erro na aplicacao");
}
}
//Metodo que desabilita os campos textField
public void desabilitaCampos(){
jTextFieldCpf.setEditable(false);
jComboBoxAssunto.setEditable(false);
jComboBoxSubCategoria.setEditable(false);
jTextAreaAnuncio.setEditable(false);
jTextFieldValorServico_produto.setEditable(false);
}
//metodo que habilita os campos textField
public void habilitaCampos(){
jTextFieldCpf.setEditable(true);
jComboBoxAssunto.setEditable(true);
jComboBoxSubCategoria.setEditable(true);
jTextAreaAnuncio.setEditable(true);
jTextFieldValorServico_produto.setEditable(true);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Aplicacao().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButtonCadastrar;
private javax.swing.JButton jButtonLimpar;
private javax.swing.JButton jButtonNovo;
private javax.swing.JComboBox jComboBoxAssunto;
private javax.swing.JComboBox jComboBoxSubCategoria;
private javax.swing.JLabel jLabelAnuncio;
private javax.swing.JLabel jLabelAssunto;
private javax.swing.JLabel jLabelCpf;
private javax.swing.JLabel jLabelFotot;
private javax.swing.JLabel jLabelSubCategoria;
private javax.swing.JLabel jLabelValorAnuncio;
private javax.swing.JLabel jLabelValorServico_produto;
private javax.swing.JPanel jPanelBotoes;
private javax.swing.JPanel jPanelDadosAnuncio;
private javax.swing.JPanel jPanelprincipal;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextAreaAnuncio;
private javax.swing.JTextField jTextFieldCpf;
private javax.swing.JTextField jTextFieldValorServico_produto;
// End of variables declaration
}
Como devo proceder para corrigir este erro em minha aplicação?
Desde já agradeço.