The field is not visible

2 respostas
maresp

Gerei um .jar com as minhas classes que fazem a persistência no db. Importei o .jar para o meu projeto. Criei uma nova classe no projeto que ‘extends’ uma determinada classe do meu .jar, só que quando tento acessar um atributo public que é herdado da classe pai eu tenho a msg ‘the field xxx is not visible’. Pq?

2 Respostas

Leandro_Rangel_Santo

tem certeza que o atributo é public ?
manda o fonte do filho e do pai

maresp
essa é minha classe que coloquei dentro do .jar
package br.unipar.avaliacao.model.dao;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;

public class GenericDAO {
	
	// nome das propriedades no arquivo db*.propoerties
	private static final String DRIVER = "driver";
	private static final String URL = "url";
	private static final String USER = "user";
	private static final String PASS = "pass";
	private static final String DATA_FORMATO = "data.formato";
	private static final String QUERY_FILE = "queryFile";
	
	// variaveis de conexao com database
	public String driver;
	public String url;
	public String user;
	public String pass;
	public String dataFormato;
	public String queryFile;
 	public String tabela;
	
	// conexao
	public Connection conn;
	
	public GenericDAO() {}
	
	public GenericDAO(String pathConfig) throws IOException,
			FileNotFoundException, ClassNotFoundException {
		// lendo o arquivo de configurações
		driver = getProp(pathConfig, DRIVER);
		url = getProp(pathConfig, URL);
		user = getProp(pathConfig, USER);
		pass = getProp(pathConfig, PASS);
		dataFormato = getProp(pathConfig, DATA_FORMATO);
		queryFile = getProp(pathConfig, QUERY_FILE);
		Class.forName(driver);
	}
	
	public GenericDAO(String pathConfig, String tabela)
		throws IOException, FileNotFoundException, ClassNotFoundException {
		// lendo o arquivo de configurações
		driver = getProp(pathConfig, DRIVER);
		url = getProp(pathConfig, URL);
		user = getProp(pathConfig, USER);
		pass = getProp(pathConfig, PASS);
		dataFormato = getProp(pathConfig, DATA_FORMATO);
		queryFile = getProp(pathConfig, QUERY_FILE);
		Class.forName(driver);
		this.tabela = tabela;
	}
	
	public void conectar() throws SQLException {
		conn = DriverManager.getConnection(url, user, pass);
	}
	
	public void desconectar() throws SQLException {
		conn.close();
	}
	
	public String getProp(String path, String prop) throws
		IOException, FileNotFoundException {
		File file = new File(path);
		Properties props = new Properties();
		FileInputStream fis = new FileInputStream(file);
		props.load(fis);
		String property = props.getProperty(prop);
		fis.close();
		return property;
	}
	
	public synchronized int pkGenerator(String sequencia) throws FileNotFoundException, IOException, SQLException {
		String sql = getProp(queryFile,"sequencia.update");
		PreparedStatement pSt = conn.prepareStatement(sql);
		pSt.setString(1,sequencia);
		/* cria uma sequencia caso ela não exista
		 * com o valor inicial 1
		 */
		if( pSt.executeUpdate() == 0 ) {
			sql = getProp(queryFile,"sequencia.insert");
			pSt = conn.prepareStatement(sql);
			pSt.setString(1,sequencia);
			pSt.setInt(2,1);
			pSt.executeUpdate();
		}
		
		sql = getProp(queryFile,"sequencia.select");
		pSt = conn.prepareStatement(sql);
		pSt.setString(1,sequencia);
		ResultSet rs = pSt.executeQuery();
		int codSeq = 0;
		while(rs.next()) {
			codSeq = rs.getInt(1);
		}
		pSt.close();
		rs.close();
		return codSeq;
	}
}

Aqui está o trecho da outra classe onde eu tento acessar os atributos queryFile e tabela diretamente:

package br.unipar.maval.model.dao;

import java.sql.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import br.unipar.avaliacao.model.dao.*;

public class ResultadoDAO extends GenericDAO {
...
public int selectTotalCount() throws FileNotFoundException, IOException, SQLException {
		int count = 0;
		String sql = getProp(queryFile,TOTAL_COUNT);
		sql.replaceAll("$tabela",tabela);
		PreparedStatement pSt = conn.prepareStatement(sql);
		ResultSet rs = pSt.executeQuery();
		while(rs.next()) {
			count = rs.getInt(1);
		}
		rs.close();
		pSt.close();
		return count;
	}
...
}
Criado 26 de setembro de 2003
Ultima resposta 29 de set. de 2003
Respostas 2
Participantes 2