|
|
How to use SimpleJdbcTemplate#query without arguments
Hi,
i am using SimpleJdbcTemplate to query the database with the following sql statement quot;select state from Statesquot;. This returns a resultset of varchar states. no arguments are required.
How do i use SimpleJdbcTemplate#query statement without having to pass arguments. All the overloaded methods expect some sort of an argumentCode:
Listlt;Stringgt; states = template.query(quot;select state from statesquot;, new ParameterizedRowMapperlt;Stringgt;() { public String mapRow(ResultSet rs, int i) throws SqlException { return rs.getString(quot;statequot;); }
}, args);
Is there any alternate way to do this?
If you're using Java 5, the method singure of query isCode:
query(String sql, ParameterizedRowMapperlt;Tgt; rm, Object... args)
The last parameter is a quot;varargsquot; (variable length argument lists) meaning you can put 0 or more objects there. So you can leave it out in your case. If you're using Java 4 then you have to pass an empty array (a little ugly but otherwise harmless)
SimpleJdbcTemplate is anyway for Java5+ only.
/*** Java-5-based convenience wrapper for the classic Spring* {@link org..jdbc.core.JdbcTemplate},* taking advantage of varargs and autoboxing, and exposing only the most* commonly required operations in order to simplify JdbcTemplate usage.Originally Posted by sambrodkinIf you're using Java 5, the method singure of query isCode:
query(String sql, ParameterizedRowMapperlt;Tgt; rm, Object... args)
The last parameter is a quot;varargsquot; (variable length argument lists) meaning you can put 0 or more objects there. So you can leave it out in your case. If you're using Java 4 then you have to pass an empty array (a little ugly but otherwise harmless) |
|