Bom dia!
Alguém pode me ajudar a extender a Classe ManutencaoTabela?
Perdoe-me pela ignorância, mas não estou conseguindo.
Digam-me por favor como faço para [color=red]Usuario[/color] extender [color=red]ManutencaoTabela[/color].
Mostre-me um exemplo simples por favor.
Desde já muito obrigado.
/*
* Usuario.java
*
* Created on 16 de Junho de 2007, 21:58
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package tabelas;
import bancodados.BancoDados;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.JOptionPane;
/**
*
* @author Paulo Roberto
*/
public class Usuario {
private String strNomeTabela;
private Connection cnnConexao;
private Integer intMatriculaChv;
private String strNome;
private String strNomeGuerra;
private GregorianCalendar gcDataCadastramento;
private String strSenha;
private GregorianCalendar gcValidadeSenha;
/** Creates a new instance of Usuario */
public Usuario() {
this.strNomeTabela = "tb_Usuarios";
}
public Usuario(final Integer intMatriculaChv, final Connection cnnConexao) {
this.strNomeTabela = "tb_Usuarios";
this.cnnConexao = cnnConexao;
this.intMatriculaChv = intMatriculaChv;
StringBuffer sbSQL = new StringBuffer()
.append("SELECT Usuario.* ")
.append("FROM Tb_Usuarios Usuario ")
.append("WHERE Usuario.MatriculaChv = " + this.intMatriculaChv.toString());
ResultSet rs = BancoDados.FabricaCosulta(sbSQL, cnnConexao);
try {
// if (rs.isBeforeFirst()) {
while (rs.next()) {
//Atribui valores aos atributos da classe
this.setMatriculaChv(rs.getInt("MatriculaChv"));
this.setNome(rs.getString("Nome"));
this.setNomeGuerra(rs.getString("NomeGuerra"));
GregorianCalendar gc = new GregorianCalendar();
gc.setTime(rs.getDate("DataCadastramento"));
this.setDataCadastramento(gc);
this.setSenha(rs.getString("Senha"));
gc.setTime(rs.getDate("ValidadeSenha"));
this.setValidadeSenha(gc);
}
// }
} catch (SQLException errorSQL) {
JOptionPane.showMessageDialog(null, errorSQL.getMessage(), "Erro SQL", JOptionPane.ERROR_MESSAGE);
errorSQL.printStackTrace();
}
}
public String getNomeTabela() {
return this.strNomeTabela;
}
public Integer getMatriculaChv() {
return this.intMatriculaChv;
}
public void setMatriculaChv(Integer intMatriculaChv) {
this.intMatriculaChv = intMatriculaChv;
}
public String getNome() {
return this.strNome;
}
public void setNome(String strNome) {
this.strNome = strNome;
}
public String getNomeGuerra() {
return this.strNomeGuerra;
}
public void setNomeGuerra(String strNomeGuerra) {
this.strNomeGuerra = strNomeGuerra;
}
public GregorianCalendar getDataCadastramento() {
return this.gcDataCadastramento;
}
public void setDataCadastramento(GregorianCalendar gcDataCadastramento) {
this.gcDataCadastramento = gcDataCadastramento;
}
public String getSenha() {
return this.strSenha;
}
public void setSenha(String strSenha) {
this.strSenha = strSenha;
}
public GregorianCalendar getValidadeSenha() {
return this.gcValidadeSenha;
}
public void setValidadeSenha(GregorianCalendar gcValidadeSenha) {
this.gcValidadeSenha = gcValidadeSenha;
}
}
/*
* ManutencaoTabela.java
*
* Created on 23 de Junho de 2007, 21:01
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package manutencoes;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.ParameterMetaData;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.LinkedHashMap;
import javax.swing.JOptionPane;
/**
*
* @author Paulo Roberto
*/
public class ManutencaoTabela {
private Object tbTabela;
private Class clsTabela;
private String strNomeTabela;
private LinkedHashMap lhmAtributosClasse;
private Connection Conexao;
public ManutencaoTabela(final Object Tabela, final Connection Conexao) {
this.tbTabela = Tabela;
this.clsTabela = Tabela.getClass();
this.lhmAtributosClasse = this.getAtributosClasse();
this.Conexao = Conexao;
}
public void IncluiRegistro() {
this.ExecutaTransacao(this.PreparaInclusaoRegistro());
}
public void AtualizaRegistro() {
this.ExecutaTransacao(this.PreparaAlteracaoRegistro());
}
public void ExcluiRegistro() {
this.ExecutaTransacao(this.PreparaExclusaoRegistro());
}
protected void ExecutaTransacao(final String strSQL) {
String strNomeAtributo = new String();
}
protected String PreparaInclusaoRegistro() {
StringBuffer sbSQL = new StringBuffer();
return sbSQL.toString();
}
protected String PreparaAlteracaoRegistro() {
StringBuffer sbSQL = new StringBuffer();
return sbSQL.toString();
}
protected String PreparaExclusaoRegistro() {
StringBuffer sbSQL = new StringBuffer();
return sbSQL.toString();
}
protected LinkedHashMap getAtributosClasse() {
LinkedHashMap lhmAtributosClasse = new LinkedHashMap();
return lhmAtributosClasse;
}
protected PreparedStatement TrataParametro(final PreparedStatement pstmt, final int i, final Object Objeto) throws SQLException {
PreparedStatement pstmt2 = pstmt;
return pstmt2;
}
}