Hola ...
Tengo 3 Classes en un: package jterminal;
pero existe una la cual no me permite acceder a los métodos públicos desde otra.
Aquí les envío la classe con problemas:
package jterminal;
import java.sql.*;
import java.util.*;
/**
* <p>Title: BD</p>
* <p>Description: LA CLASE BD REALIZA TODAS LAS MANIPULACIONES CON LA
* BASE DE DATOS</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: Pedro</p>
* @author Pedro L. García
* @version 1.0
*/
public class BD {
Connection conn = null;
Mask mask = new Mask();
private ArrayList ListToFile = new ArrayList();
private ArrayList ListToScreen = new ArrayList();
public BD() {
Connection conn = null;
String url = "jdbc:informix-sqli://website:1533/maq:INFORMIXSERVER=website;user=maq;password=rmm12 43";
try
{
Class.forName("com.informix.jdbc.IfxDriver");
}
catch (Exception e) {
System.out.println("ERROR: Al cargar el Driver JDBC.");
e.printStackTrace();
return;
}
try
{
conn = DriverManager.getConnection(url);
}
catch (SQLException e)
{
System.out.println("FAILED: failed to connect!");
}
this.SelectHome (conn);
this.SelectToFile(conn);
}
/**
* DEVUELVE UN ARRAYLIST PARA INSERTAR EN EL FICHERO MAQUINAS.DAT
* @param arg
* @return
*/
private void SelectToFile(Connection conn){
String codrut = new String("010142");
String codmaq, codloc;
double fpaccc = 0;
double ideccc = 0;
StringBuffer listToFile = new StringBuffer(255);
PreparedStatement pstmt_maq, pstmt_moc, pstmt_ccc;
ResultSet rs_maq, rs_moc, rs_ccc;
try{
pstmt_maq = conn.prepareStatement("select codmaq, nommdq, codloc, nomloc, tipcdr, va1cdr, va2cdr, va3cdr, "+
" va4cdr, co1mdq, co2mdq, co3mdq, co4mdq from maq, loc, cdr, mdq " +
"where codmdq = modmaq and loccdr = codloc and TODAY between feccdr and fincdr and codmaq = maqcdr and codloc = barmaq and estmaq=0 and almmaq='N' "+
"and barmaq IN (select codloc from loc where actloc='S' and rutloc IN "+
"(?)) order by nomloc, codmaq, codloc");
pstmt_maq.setString(1, codrut);
rs_maq = pstmt_maq.executeQuery();
pstmt_moc = conn.prepareStatement("Select c1emoc, c1smoc, c2emoc, c2smoc, c3emoc, c3smoc,"+
" c4emoc, c4smoc from moc where maqmoc = ? and "+
" fecmoc = (select max(fecmoc) from moc where maqmoc = ?)");
pstmt_ccc = conn.prepareStatement("Select fpaccc, ideccc from ccc where locccc = ? " +
" and firccc <= TODAY and liqccc <> 'S'");
while(rs_maq.next()){
codmaq = rs_maq.getString("codmaq");
codloc = rs_maq.getString("codloc");
pstmt_moc.setString(1, codmaq);
pstmt_moc.setString(2, codmaq);
rs_moc = pstmt_moc.executeQuery();
/*
Lleno el ArrayList que escribiré en el fichero
*/
listToFile.append(mask.mask(codmaq, 9));
listToFile.append(mask.mask(rs_maq.getString("nomm dq"), 25));
listToFile.append(mask.mask(rs_maq.getString("codl oc"), 4));
listToFile.append(mask.mask(rs_maq.getString("noml oc"), 25));
listToFile.append(mask.mask(rs_maq.getString("tipc dr"), 1));
listToFile.append(mask.mask(rs_maq.getDouble("va1c dr"), "00000.00"));
listToFile.append(mask.mask(rs_maq.getDouble("va2c dr"), "00000.00"));
listToFile.append(mask.mask(rs_maq.getDouble("va3c dr"), "00000.00"));
listToFile.append(mask.mask(rs_maq.getDouble("va4c dr"), "00000.00"));
while(rs_moc.next()){
listToFile.append(mask.mask(rs_moc.getDouble("c1em oc"), "00000000"));
listToFile.append(mask.mask(rs_moc.getDouble("c1sm oc"), "00000000"));
listToFile.append(mask.mask(rs_moc.getDouble("c2em oc"), "00000000"));
listToFile.append(mask.mask(rs_moc.getDouble("c2sm oc"), "00000000"));
listToFile.append(mask.mask(rs_moc.getDouble("c3em oc"), "00000000"));
listToFile.append(mask.mask(rs_moc.getDouble("c3sm oc"), "00000000"));
listToFile.append(mask.mask(rs_moc.getDouble("c4em oc"), "00000000"));
listToFile.append(mask.mask(rs_moc.getDouble("c4sm oc"), "00000000"));
}
listToFile.append(mask.mask(rs_maq.getDouble("co1m dq"), "00000.00"));
listToFile.append(mask.mask(rs_maq.getDouble("co2m dq"), "00000.00"));
listToFile.append(mask.mask(rs_maq.getDouble("co3m dq"), "00000.00"));
listToFile.append(mask.mask(rs_maq.getDouble("co4m dq"), "00000.00"));
pstmt_ccc.setString( 1, codloc);
rs_ccc = pstmt_ccc.executeQuery();
boolean brs_ccc = rs_ccc.next();
if (brs_ccc) {
listToFile.append(mask.mask(rs_ccc.getDouble("fpac cc"),"0"));
listToFile.append(mask.mask(rs_ccc.getDouble("idec cc"),"00000.00"));
}
else {
listToFile.append("0");
listToFile.append("00000.00");
}
this.ListToFile.add(listToFile.toString());
listToFile.delete(0,254);
}
}
catch (SQLException e)
{
System.out.println("ERROR: Fetch statement failed: " + e.getMessage() +" " + e.getErrorCode());
}
}
/**
* DEVUELVE EL ARRAYLIST DE LA UNIÓN DE LOS SIGUIENTES SELECT
* CODRUT FROM RUT
* NOMOPE FROM OPE
* NOMDEL FROM DEL
* DIASEM DIAS DE LA SEMANA SEGUN CODRUT.SUBSTRING(5)
* NOMPER FROM PER
* @param conn
* @return
*/
private void SelectHome (Connection conn) {
Statement stmt_rut;
ResultSet rs_rut, rs_ope, rs_del, rs_per;
PreparedStatement pstmt_ope, pstmt_del, pstmt_per;
StringBuffer lineaToScreen = new StringBuffer();
try
{
stmt_rut = conn.createStatement();
rs_rut = stmt_rut.executeQuery("Select * from rut");
pstmt_ope = conn.prepareStatement("Select * from ope where codope = ?");
pstmt_del = conn.prepareStatement("Select * from del where coddel = ?");
pstmt_per = conn.prepareStatement("Select * from per where codper = ?");
while(rs_rut.next()) {
String codrut = rs_rut.getString("codrut");
String perrut = rs_rut.getString("perrut");
lineaToScreen.append( mask.mask(codrut, 8));
pstmt_ope.setString(1, this.codope(codrut));
rs_ope = pstmt_ope.executeQuery();
pstmt_del.setString(1, this.coddel(codrut));
rs_del = pstmt_del.executeQuery();
pstmt_per.setString(1, perrut);
rs_per = pstmt_per.executeQuery();
while(rs_ope.next()){
lineaToScreen.append(mask.mask(rs_ope.getString("n omope"),30));
}
while(rs_del.next()){
lineaToScreen.append(mask.mask(rs_del.getString("n omdel"),13));
}
lineaToScreen.append(mask.mask(this.diasem(codrut) ,13));
while(rs_per.next()){
lineaToScreen.append(mask.mask(rs_per.getString("n omper"), 16));
}
this.ListToScreen.add(lineaToScreen.toString());
lineaToScreen.delete(0,254);
}
rs_rut.close();
}
catch (SQLException e)
{
System.out.println("FAILED: Fetch statement failed: " + e.getMessage());
}
}
/**
* DEVUELVE LOS CARACTERES 1 Y 2 DEL CAMPO codrut
* @param codrut
* @return
*/
private String codope (String codrut) {
return (codrut.substring(1, 2));
}
/**
* DEVUELVO EL LOS CARACTERES 2 Y 3 DEL CAMPO codrut
* @param codrut
* @return
*/
private String coddel (String codrut) {
return (codrut.substring(2, 4));
}
/**
* DEVUELVO EL DIA DE LA SEMNA DE LUNES A VIERNES
* SEGÚN EL ÚLTIMO CARACTER DEL CAMPO codrut
* @param codrut
* @return
*/
private String diasem (String codrut) {
int item = new Integer(codrut.substring(5)).intValue();
String diasem[] = {"Lunes","Martes","Miércoles","Jueves","Viernes "};
return (diasem[item-1]);
}
public ArrayList OutToFile() {
return ListToFile;
}
public ArrayList OutToScreen() {
return ListToScreen;
}
public void ver() {
Iterator alIt = ListToScreen.iterator();
while (alIt.hasNext()) {
System.out.println(alIt.next());
}
Iterator It = ListToFile.iterator();
while (It.hasNext()) {
System.out.println(It.next());
}
}
public static void main(String[] args)
{
new BD();
}
}