Boa tarde a todos.
Tenho duas classes que na verdade gostaria que fosse uma, ou seja, desejo o conteudo de "ManutencaoTabelas" fosse herdado para "Usuario".
Como fazer isso, segundo código abaixo?
Obrigado.
[color=red]ManutencaoTabelas[/color]
/*
* 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.PreparedStatement;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Iterator;
import javax.swing.JOptionPane;
/**
*
* @author Paulo Roberto
*/
public class ManutencaoTabela {
private Object Tabela;
private Connection Conexao;
public ManutencaoTabela(final Object Tabela, final Connection Conexao) {
this.Tabela = Tabela;
this.Conexao = Conexao;
}
public void IncluiRegistro() {
this.ExecutaTransacao(this.PreparaInclusaoRegistro());
}
public void AtualizaRegistro() {
this.ExecutaTransacao(this.PreparaAlteracaoRegistro());
}
public void ExcluiRegistro() {
//
}
private void ExecutaTransacao(final String sbSQL) {
}
private String PreparaInclusaoRegistro() {
StringBuffer sbSQL = new StringBuffer();
//...
return sbSQL.toString();
}
private String PreparaAlteracaoRegistro() {
StringBuffer sbSQL = new StringBuffer()
// ...
return sbSQL.toString();
}
private HashMap LeColunasTabela() {
HashMap hmCamposValores = new HashMap();
return hmCamposValores;
}
private String TrataDadosAGravar(final Object ObjetoATratar) {
String ObjetoTratado = new String();
return ObjetoTratado;
}
}
[color=red]Usuario[/color]
[code]
[/*
- 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 java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.GregorianCalendar;
import javax.swing.JOptionPane;
import manutencoes.ManutencaoTabela;
/**
*
-
@author Paulo Roberto
*/
public class Usuario {
protected String NomeTabela;
private Integer Matricula;
private String Nome;
private String NomeGuerra;
private GregorianCalendar DataCadastramento;
private String Senha;
private GregorianCalendar ValidadeSenha;/** Creates a new instance of Usuario */
public Usuario() {
this.NomeTabela = “tb_Usuarios”;
}public Usuario(final Integer Matricula, final Connection Conexao) {
this.NomeTabela = “tb_Usuarios”;
// this.getUsuario(Matricula, Conexao);
}public String getNomeTabela() {
return this.NomeTabela;
}public Integer getMatricula() {
return this.Matricula;
}public void setMatricula(Integer Matricula) {
this.Matricula = Matricula;
}public String getNome() {
return this.Nome;
}public void setNome(String Nome) {
this.Nome = Nome;
}public String getNomeGuerra() {
return this.NomeGuerra;
}public void setNomeGuerra(String NomeGuerra) {
this.NomeGuerra = NomeGuerra;
}public GregorianCalendar getDataCadastramento() {
return this.DataCadastramento;
}public void setDataCadastramento(GregorianCalendar DataCadastramento) {
this.DataCadastramento = DataCadastramento;
}public String getSenha() {
return this.Senha;
}public void setSenha(String Senha) {
this.Senha = Senha;
}public GregorianCalendar getValidadeSenha() {
return this.ValidadeSenha;
}public void setValidadeSenha(GregorianCalendar ValidadeSenha) {
this.ValidadeSenha = ValidadeSenha;
}public Usuario getUsuario(final Integer Matricula, final Connection Conexao) {
Usuario Usr = new Usuario(Matricula, Conexao);return Usr;
}
public void setUsuario(Integer Matricula, Connection Conexao) {
StringBuffer sbSQL = new StringBuffer()
.append("SELECT Usuario.* ")
.append("FROM Tb_Usuarios Usuario ")
.append("WHERE Usuario.Matricula = " + Matricula.toString());try { //Prepara transação PreparedStatement pstmt = Conexao.prepareStatement(sbSQL.toString()); //Atribui valores aos Parâmetros //stmt.setString(1, ""); //Cria resultado ResultSet rs = pstmt.executeQuery(); if (rs.isBeforeFirst()) { while (rs.next()) { System.out.println(rs.getString("Nome")); //Atribui valores as campos da classe this.setMatricula(rs.getInt("Matricula")); this.setNome(rs.getString("Nome")); this.setNomeGuerra(rs.getString("NomeGuerra")); this.setDataCadastramento(new GregorianCalendar(2007, 3, 14)); this.setSenha(rs.getString("Senha")); this.setValidadeSenha(new GregorianCalendar(2007, 3, 14)); } } //Consolida transação Conexao.commit(); //Fecha conexão pstmt.close(); //Mostra String SQL System.out.println(sbSQL); } catch (SQLException errorSQL) { JOptionPane.showMessageDialog(null, errorSQL.getMessage(), "Erro SQL", JOptionPane.ERROR_MESSAGE); errorSQL.printStackTrace(); }
}
}
/code]