Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions src/main/java/hawk/service/SearchService.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,11 @@ public List<Item> search(Search search) {
@Override
public List<Item> execute(Connection connection) throws SQLException {
List<Item> items = new ArrayList<>();
// The wrong way
String query = "select id, name, description from ITEM where description like '%" +
search.getSearchText() + "%'";

LOGGER.log(Level.INFO, "SQL Query: {0}", query);;
ResultSet rs = connection
.createStatement()
.executeQuery(query);

/* The righter way, should probably use built in Data Model for this, but this is safe
String query = "select id, name, description from ITEM where description like ?";
PreparedStatement statement = connection.prepareStatement(query);
statement.setString(1, "%" + search.getSearchText() + "%");
LOGGER.log(Level.INFO, "SQL Query {0}", statement);
ResultSet rs = statement.executeQuery();
*/

while (rs.next()) {
items.add(new Item(rs.getLong("id"), rs.getString("name"), rs.getString("description")));
Expand Down
Loading