Olá pessoal, Gostaria de saber se o codigo abaixo esta certo no encapsulmento…
Valeu!
[code]
package banco;
import layout.*;
import java.sql.;
import javax.swing.;
import java.awt.*;
public class CadastrarClientes extends JFrame{
public static String codetext;
public static String datatext;
private int codigo;
private String data;
private String nome;
private String rg;
private String cpf;
private String endereco;
private String cep;
private String bairro;
private String telefone;
private String celular;
public void setCodigo(int codigo) {
this.codigo = codigo;
}
public int getCodigo() {
return this.codigo;
}
public void setData(String data) {
this.data = data;
}
public String getData() {
return this.data;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getNome() {
return this.nome;
}
public void setRg(String rg) {
this.rg = rg;
}
public String getRg() {
return this.rg;
}
public void setCpf(String cpf) {
this.cpf = cpf;
}
public String getCpf() {
return this.cpf;
}
public void setEndereco(String endereco) {
this.endereco = endereco;
}
public String getEndereco() {
return this.endereco;
}
public void setCep(String cep) {
this.cep = cep;
}
public String getCep() {
return this.cep;
}
public void setBairro(String bairro) {
this.bairro = bairro;
}
public String getBairro() {
return this.bairro;
}
public void setTelefone(String telefone) {
this.telefone = telefone;
}
public String getTelefone() {
return this.telefone;
}
public void setCelular(String celular) {
this.celular = celular;
}
public String getCelular() {
return this.celular;
}
public void cadastrarClientes()
{
Connection conexao = null;
Statement comando = null;
try
{
Class.forName("com.mysql.jdbc.Driver");
conexao = DriverManager.getConnection("jdbc:mysql://127.0.0.1/locadora?user=root&password=zerocodetege");
comando = conexao.createStatement();
Statement stmt = conexao.createStatement();
String sql = ("insert into clientes (codigo,data,nome,rg,cpf,endereco,cep,bairro,telefone,celular) values ('"+getCodigo()+"','"+getData()+"','"+getNome()+"','"+getRg()+"','"+getCpf()+"','"+getEndereco()+"','"+getCep()+"','"+getBairro()+"','"+getTelefone()+"','"+getCelular()+"')");
stmt.executeUpdate(sql);
Clientes.btnDependentes.setEnabled(true);
codetext = Integer.toString(getCodigo());
datatext = getData();
String texto = " Cadastro Efetuado com Sucesso!";
JOptionPane.showMessageDialog(null,texto,"Aviso:",JOptionPane.INFORMATION_MESSAGE,null);
}
catch(SQLException e)
{
String texto = " Cliente Ja Cadastrado!";
JOptionPane.showMessageDialog(null,texto,"Aviso:",JOptionPane.WARNING_MESSAGE,null);
System.out.println(e.getMessage());
}
catch(NumberFormatException e)
{
String txt = "Insira os Dados Corretamente!";
JOptionPane.showMessageDialog(null,txt,"Aviso:",JOptionPane.INFORMATION_MESSAGE);
}
catch(ClassNotFoundException e)
{
System.out.println("O Drive não foi Encontrado!");
}
finally
{
try
{
if (comando !=null)
comando.close();
if (conexao !=null && !conexao.isClosed())
conexao.close();
}
catch(SQLException event)
{
}
}
}
}
[/code]