I am creating a method to obtain the records of clients that have a certain userid , the client table contains the columns: clientid,name,userid also the Client class contains the 3 parameters clientid,name,userid .
But the query that I created to obtain said data seems to have some error and I don't know what it is.
The method:
@SuppressWarnings({ "unchecked", "rawtypes" })
public Set getClientsByUserID(String userid) {
Set clients = new HashSet();
try {
String queryString = "SELECT * FROM clients WHERE=?";
connection = getConnection();
ptmt = connection.prepareStatement(queryString);
ptmt.setString(1, userid);
resultSet = ptmt.executeQuery();
while (resultSet.next()) {
Client client = extractClientFromResultSet(resultSet);
clients.add(client);
}
return clients;
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (resultSet != null)
resultSet.close();
if (ptmt != null)
ptmt.close();
if (connection != null)
connection.close();
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
The error I get:
org.postgresql.util.PSQLException: ERRORE: errore di sintassi a o presso "="
Posizione: 28
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:143)
at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:106)
at db.dao.ClientDAO.getClientsByUserID(ClientDAO.java:48)
Ok, the mistake was mine, a simple oversight when writing the query :
In the WHERE clause the name of the column is missing, that is userid , so changing:
the problem is solved.