Oi, estou tentando criar um método que retorna um usuario a partir do login mas tá dando erro. O método é:
@Override
public Usuario recuperar(String login) {
Usuario u = new Usuario();
try(Connection c = DriverManager.getConnection("jdbc:postgresql://localhost/coursera","postgres","")){
String sql ="SELECT * FROM usuario WHERE login = ?";
PreparedStatement stm = c.prepareStatement(sql);
ResultSet rs = stm.executeQuery();
u.setLogin(rs.getString("login"));
u.setEmail(rs.getString("email"));
u.setNome(rs.getString("nome"));
u.setSenha(rs.getString("senha"));
u.setPontos(rs.getInt("pontos"));
} catch (SQLException ex) {
Logger.getLogger(UsuarioDAO.class.getName()).log(Level.SEVERE, null, ex);
}
return u;
}
o erro que dá é esse:
out 29, 2016 12:07:43 PM AcessoBancoDeDadosUsuario recuperar GRAVE: null org.postgresql.util.PSQLException: Nenhum valor especificado para parâmetro 1. at org.postgresql.core.v3.SimpleParameterList.checkAllParametersSet(SimpleParameterList.java:249) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:275) at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:432) at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:358) at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:171) at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:119) at AcessoBancoDeDadosUsuario.recuperar(AcessoBancoDeDadosUsuario.java:51) at PrincipalTesteDAO.main(PrincipalTesteDAO.java:19)