org.postgresql.util.PSQLException:在此结果集中找不到列名 usuario [英] org.postgresql.util.PSQLException: The column name usuario was not found in this ResultSet
问题描述
我收到以下错误:org.postgresql.util.PSQLException: The column name usuario was not found in this ResultSet.
I am getting the following error: org.postgresql.util.PSQLException: The column name usuario was not found in this ResultSet.
但是,我在适当的类中正确声明了以下列 usuario!
However, I have the following column usuario declared properly in the appropriate classes!
UsuariosGruposDAO.class
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
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;
}
错误出现在以下行:
ugList.add((UsuariosGrupos) objectFactory(rs));
我的列表方法:
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;
}
奇怪的是,当我单独测试我的列表时,数据表显示了适当的结果.但是,当我运行整个应用程序时,没有任何显示,并且出现错误,指出在结果集中找不到 usuario 列.有什么建议吗?
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?
该表有两个字段:
Usuarios | Grupos
admin 2
admin 3
当我分离我的 jsf 代码时它显示良好,但当我将它放在一个 JSF 文件中时不显示数据.
It displays fine, when I separate my jsf code, but doesn't display the data when I have it on one JSF file.
推荐答案
您的表转储显示该字段为Usarios",但您正在执行 rs.getString("usuario")
.不应该是下面这样吗?
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")
如果这不起作用,那么我建议调试您的代码,在 getString
行上放置一个断点并查看 ResultSet
以查看字段名称是什么
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.
这篇关于org.postgresql.util.PSQLException:在此结果集中找不到列名 usuario的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!