Olá fiz essa classe Query para me ajudar a fazer as consultas e tals e a conexão para fazer a conexão;
o Problema é que quando eu chamo a classe query com o método voltar ou ultimo ele não acha o resultado mas quando eu chamo o avancar ele acha.Qual seria o erro?Já fiz tudo que eu sabia agora peço ajudas á vocês que sabem mais ainda :).
public class conexao {
private Connection con = null;
// Conectando ao Banco de Dados
public conexao(){
try{
Class.forName("org.firebirdsql.jdbc.FBDriver");
con = DriverManager.getConnection(
"jdbc:firebirdsql:localhost/3050:H:/SistemaDeImobiliaria/BdSisImo/BDSISIMO.gdb",
"SYSDBA",
"masterkey");
}catch(Exception e){
JOptionPane.showConfirmDialog(null,"Nao Acessou "+e.getMessage());
}
}
public Connection getConexao(){
return con;
}
//Desconecta do Banco de Dados
public void disconnect(){
try{
con.close();
}catch(Exception e){
JOptionPane.showMessageDialog(null,"Problemas ao encerrar a Conexão","Erro",JOptionPane.ERROR_MESSAGE);
}
}
//seta e retorna o preparedStatement do con(conexão)
public PreparedStatement pS(String sql){
PreparedStatement p = null;
try {
p = con.prepareStatement(sql);
} catch (SQLException ex) {
Logger.getLogger(conexao.class.getName()).log(Level.SEVERE, null, ex);
}
return p;
}
}
public class Query {
private Connection con;
private ResultSet rs;
private Statement stm;
//Cria uma nova Query
public Query(Connection DB){
try{
con = DB;
stm = con.createStatement();
}catch(SQLException e){
JOptionPane.showMessageDialog(null,"Problemas ao criar a Query","Erro",JOptionPane.ERROR_MESSAGE);
}
}
//Executa uma consulta
public void open(String sql){
try{
rs = stm.executeQuery(sql);
}catch(SQLException e){
JOptionPane.showMessageDialog(null,"Problemas executar a Query","Erro",JOptionPane.ERROR_MESSAGE);
}
}
//Fechando um Consulta
public void close(){
try{
stm.close();
}catch(SQLException e){
JOptionPane.showMessageDialog(null,"Problemas executar a Query","Erro",JOptionPane.ERROR_MESSAGE);
}
}
public int getIntRs(int column ){
int i=0;
try {
i= rs.getInt(column);
} catch(SQLException e) {
JOptionPane.showMessageDialog(null,"Arquivo não Encontradp");
}
return i;
}
//Prox resultado
public boolean avancar(){
boolean retorno = false;
try {
if(rs.next()){
retorno = true;
}
} catch(SQLException e) {
JOptionPane.showMessageDialog(null,"Fim de Arquivo");
}
return retorno;
}
//resultado anterior
public boolean voltar(){
boolean retorno = false;
try{
if(rs.previous()){
retorno =true;
}
}catch(SQLException e){
JOptionPane.showMessageDialog(null,"Fim de Arquivo " + e);
}
return retorno;
}
public String getStringRs(int column ){
String i="";
try {
i= rs.getString(column);
} catch(SQLException e) {
JOptionPane.showMessageDialog(null,"Arquivo não Encontradp");
}
return i;
}
public double getDoubleRs(int column ){
double i=0;
try {
i= rs.getDouble(column);
} catch(SQLException e) {
JOptionPane.showMessageDialog(null,"Arquivo não Encontradp");
}
return i;
}
public boolean ultimo(){
boolean retorno = false;
try{
if(rs.last()){
retorno =true;
}
}catch(SQLException e){
JOptionPane.showMessageDialog(null,"Fim de Arquivo " );
}
return retorno;
}
}
public class frmCadFuncionario extends javax.swing.JFrame {
private conexao BD;
private Query qryConsulta;
private Query tudo;
/** Creates new form frmCadFuncionario */
public frmCadFuncionario() {
initComponents();
//Conectando ao Banco de Dados
BD = new conexao();
//Criando uma query
qryConsulta=new Query(BD.getConexao());
tudo=new Query(BD.getConexao());
//Inicia quando o formulario inicia!!
try{
tudo.open("SELECT * FROM FUNCIONARIOS");
tudo.ultimo();
tfCod.setText(tudo.getStringRs(1));
tfNome.setText(tudo.getStringRs(2));
tfCPF.setText(tudo.getStringRs(3));
tfRG.setText(tudo.getStringRs(4));
tfEnd.setText(tudo.getStringRs(5));
tfNumero.setText(tudo.getStringRs(6));
tfBairro.setText(tudo.getStringRs(7));
tfCidade.setText(tudo.getStringRs(8));
cbECivil.setSelectedIndex(tudo.getIntRs(9));
tfTRes.setText(tudo.getStringRs(10));
tfTCom.setText(tudo.getStringRs(11));
tfCel.setText(tudo.getStringRs(12));
tfCel2.setText(tudo.getStringRs(13));
tfNCarteira.setText(tudo.getStringRs(14));
tfSTrabalho.setText(tudo.getStringRs(15));
cbCargo.setSelectedIndex(tudo.getIntRs(16));
tfSalario.setText(String.valueOf(tudo.getDoubleRs(17)));
cbSexo.setSelectedIndex(tudo.getIntRs(18));
tfDataNasc.setText(tudo.getStringRs(19));
tfDataAd.setText(tudo.getStringRs(20));
tfDataD.setText(tudo.getStringRs(21));
}catch(Exception e){
JOptionPane.showConfirmDialog(null,"Erro ao Carregar Formulario");
}
}
if(tudo.voltar()){
tfCod.setText(tudo.getStringRs(1));
tfNome.setText(tudo.getStringRs(2));
tfCPF.setText(tudo.getStringRs(3));
tfRG.setText(tudo.getStringRs(4));
tfEnd.setText(tudo.getStringRs(5));
tfNumero.setText(tudo.getStringRs(6));
tfBairro.setText(tudo.getStringRs(7));
tfCidade.setText(tudo.getStringRs(8));
cbECivil.setSelectedIndex(tudo.getIntRs(9));
tfTRes.setText(tudo.getStringRs(10));
tfTCom.setText(tudo.getStringRs(11));
tfCel.setText(tudo.getStringRs(12));
tfCel2.setText(tudo.getStringRs(13));
tfNCarteira.setText(tudo.getStringRs(14));
tfSTrabalho.setText(tudo.getStringRs(15));
cbCargo.setSelectedIndex(tudo.getIntRs(16));
tfSalario.setText(String.valueOf(tudo.getDoubleRs(17)));
cbSexo.setSelectedIndex(tudo.getIntRs(18));
tfDataNasc.setText(tudo.getStringRs(19));
tfDataAd.setText(tudo.getStringRs(20));
tfDataD.setText(tudo.getStringRs(21));
}