Reputation: 1221
I am getting the following error: org.postgresql.util.PSQLException: The column name usuario was not found in this ResultSet.
However, I have the following column usuario declared properly in the appropriate classes!
UsuariosGruposDAO.class
public Object objectFactory(ResultSet rs) {
try {
UsuariosGrupos usergroup = new UsuariosGrupos(rs.getString("usuario"), rs.getString("grupo"));
return usergroup;
} catch (SQLException e) {
e.printStackTrace();
// retorno do método
return null;
}
}
UsuariosGrupos.class
public class UsuariosGrupos {
private String usuario;
private String grupo;
public UsuariosGrupos() {
}
public UsuariosGrupos(String usuario, String grupo) {
this.usuario = usuario;
this.grupo = grupo;
}
The error appears in the following line:
ugList.add((UsuariosGrupos) objectFactory(rs));
of my List method:
List<UsuariosGrupos> ugList = null;
try {
//Conecta no banco
conn.conectar();
//Prepara o preparedStatment
stmt = (PreparedStatement) conn.getPreparedStatement("SELECT * from usuarios_grupos");
//Executa a instrucao SQL
ResultSet rs = stmt.executeQuery();
ugList = new ArrayList<UsuariosGrupos>();
//Enquanto ouver resultSet
while (rs.next()) {
ugList.add((UsuariosGrupos) objectFactory(rs));
}
System.out.println("################################UsuariosGrupos OK################################");
} catch (SQLException e) {
System.out.println("################################UsuariosGrupos Falhou################################");
e.printStackTrace();
} finally {
conn.desconectar();
}
return ugList;
}
The weird thing is when I test my List separately, the datatable displays the appropriate results. However, when I run my entire application, nothing shows up, and I get that error stating the column usuario cannot be found in the resultset. Any suggestions?
The table has two fields:
Usuarios | Grupos
admin 2
admin 3
It displays fine, when I separate my jsf code, but doesn't display the data when I have it on one JSF file.
Upvotes: 2
Views: 7614
Reputation: 116888
Your table dump shows the field as "Usarios" but you are doing a rs.getString("usuario")
. Shouldln't that be the following?
rs.getString("usuarios")
If that doesn't work then I would recommend debugging your code, putting a breakpoint on the getString
line and looking at the ResultSet
to see what the field names are there.
Upvotes: 5