JDBC PreparedStatement Select erro
Pessoal, to aprendendo java web agora, e fiz o seguinte código:
public boolean logarUsuario(Usuario usuario) throws Exception {
PreparedStatement ps = null;
try {
String SQL = "SELECT id FROM usuario WHERE nome =? and senha =?";
ps = this.conn.prepareStatement(SQL);
ps.setString(1, usuario.getLogin());
ps.setString(2, usuario.getPassword());
ps.executeQuery(SQL);
ResultSet rs = ps.getResultSet();
boolean usuarioLogado = Boolean.valueOf(SQL);
return usuarioLogado;
} catch (SQLException sqle) {
throw new Exception("Erro ao gravar dados: " + sqle);
} finally {
if (ps != null) {
ps.close();
}
ConnectionFactory.closeConnection(this.conn);
}
}
Esse está dando o seguinte erro:
java.lang.Exception: Erro ao gravar dados: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1
Mas o insert está funcionando perfeitamente, e também tem os '?' nele.
E o meu outro select sem where funciona tbm.
Procurei na net mas não achei algo que ajudasse.
Discussão (7)
Carregando comentários...