Vectors in java

I have this method inside a class java:

public Vector MostrarNombresEquipos ( ){

boolean resultado = false;

ConexionBD consulta = new ConexionBD();

Vector Valores = new Vector();

try{

consulta.EstablecerConexion();

ResultSet otraRes = consulta.ejecutaConsulta("SELECT * FROM EQUIPO");

Valores.removeAllElements();

while(otraRes.next())

{

resultado = true;

Equipo nuevo_equipo = new Equipo();

nuevo_equipo.setCodigoeq((Integer)otraRes.getObject(1));

nuevo_equipo.setMarca(otraRes.getString(2));

nuevo_equipo.setModelo(otraRes.getString(3));

nuevo_equipo.setProcesador(otraRes.getString(4));

nuevo_equipo.setVelocidad(otraRes.getString(5));

Valores.addElement(nuevo_equipo);

}

consulta.CerrarConexion();

otraRes.close();

}catch(SQLException e){

System.out.println("Excepcion capturada de SQL: " + e);

}

if(resultado)

return Valores;

else return null;

}

On having compiled it(he,she) gives me this mistake:

C:\Archivos de programa\Apache Software Foundation\Tomcat 5.0\webapps\java4try\W

EB-INF\classes\inventarioBD>javac *.java

Note: EquipoBD.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

Which is the mistake? Because I am not capable of find.thank you

[1416 byte] By [nenukaa] at [2007-10-3 2:21:52]
# 1

It is a warning, your code does compile and will run.

The warning has probably to do with the fact you have JDK 1.5 installed, and are not using generics (http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html). Compile your code with the -Xlint:unchecked option to see the details of the warning.

Try something like this:

public Vector<Equipo> MostrarNombresEquipos() {

// ...

Vector<Equipo> Valores = new Vector<Equipo>();

// ...

return resultado ? Valores : null;

}

One more thing: your code is hard to read. Not only because you didn't use code-tages, but you don't follow the Java code conventions. Check out this link:

http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html

Good luck.

prometheuzza at 2007-7-14 19:20:50 > top of Java-index,Java Essentials,New To Java...
# 2

Hi,

You are compiling with JDK 1.5, and that means that you should use generics. The Vector should be declared as:

Vector<Equipo> valores = new Vector<Equipo>();

(Not that I also changed from Valores to valores, attributes and variables should start with lower case)

Kaj

kajbja at 2007-7-14 19:20:50 > top of Java-index,Java Essentials,New To Java...