Announcement Announcement Module
Collapse
No announcement yet.
JDBCTemplate and Postgres query with "where in " Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JDBCTemplate and Postgres query with "where in "

    Please advise how to implement with help of JDBCTemplate psql query with " where in " clause
    for example:
    "select * from product where category in ('comp','harddrive','monitor');"

    Thanks

  • #2
    Hi, I have the same question. The documentation / tutorials / API does not mention this at all.

    I have tried something like this. Take the dynamic list of strings and format it as a single string like:
    Code:
    String params = convert(List<String> params);
    Code:
    // produce something like this for params string:
    'value1', 'value2', 'value3'
    Then my query is like:

    Code:
    String SQL = SELECT * FROM TABLE WHERE COL IN (?);
    I try to substitute the string above for the '?', but I get nothing back.

    For example:
    Code:
    List list = getJdbcTemplate().query(
    	SQL, 
    	new Object[] {params}, 
    	new RowMapper() {
    		@Override
    		public Object mapRow(ResultSet rs, int rowNum) throws SQLException, DataAccessException {
    			return rs.getString(1);
    		}
    	}
    );
    If I execute the query outside Java against the database, it returns rows. My RowMapper#mapRow() never gets called.

    How do you do this with JdbcTemplate?

    Comment

    Working...
    X