Skip to content

Instantly share code, notes, and snippets.

@dnaismyth
Created October 28, 2017 18:10
Show Gist options
  • Select an option

  • Save dnaismyth/a0fde0e86291196adc9731f1f224e741 to your computer and use it in GitHub Desktop.

Select an option

Save dnaismyth/a0fde0e86291196adc9731f1f224e741 to your computer and use it in GitHub Desktop.
Adding our RowMapper and SQL query
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import tutorial.springsetup.entity.Game;
@Repository
public class GameJDBCRepository extends BaseJDBCRepository {
private final String SQL_SEARCH_BY_DESCRIPTION = "SELECT description, id, title FROM game g WHERE lower(g.description) LIKE lower(:desc);";
private class GameRowMapper implements RowMapper<Game> {
public Game mapRow(ResultSet rs, int rowNum) throws SQLException {
Game game = new Game();
game.setDescription(rs.getString("description"));
game.setId(rs.getLong("id"));
game.setTitle(rs.getString("title"));
return game;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment