How do I send these data from two tables to a List and how do I print them in the xhtml?
What I need is that you bring me this information Ex:
User Table Name: Juan IdCargo: 1
Cargo Tables IdLoad: 1 Name: Administrator
Result: User.Name Cargo.Name - > Juan Administrator
The query would be:
SELECT User.Name, Position.Name FROM User inner join Cargo on User.IdCargo = Cargo.IdCargo
I have the following code:
public List<Objeto> getUsuarios(){
List Usuarios<Objeto> = new ArrayList<>();
try
{
Connection conexion=this.getConection();
String Query="SELECT Usuario.IdUsuario,Usuario.Nombre,Cargo.Nombre FROM Usuario inner join Cargo on Usuario.IdCargo = cargo.IdCargo";
Statement sentenciaSQL = conexion.createStatement();
ResultSet cdr = sentenciaSQL.executeQuery(Query);
while(cdr.next())
{
BeanUsuario dUsu = new BeanUsuario();
dUsu.setIdUsuario(cdr.getInt("IdUsuario"));
dUsu.setNombre(cdr.getString("Nombre"));
Usuarios.add(dUsu);
BeanCargo dCar = new BeanCargo();
dCar.setNombre(cdr.getString("Nombre"));
Usuarios.add(dCar);
}
cdr.close();
conexion.close();
}
catch (Exception e)
{
}
finally
{
return Usuarios;
}
}