That's very strange then. Here is the complete code I use that having the query problem:
Code:
public Role getRoleByName(String name) {
String query = "select * from roles where roleName = ?";
// this has problem supporting utf8 string query
return getJdbcTemplate().queryForObject(query, new RoleMapper(), name);
}
this is the new one using preparedstatement, which works:
Code:
public Role getRoleByName(final String name) {
final String query = "select * from roles where roleName = ?";
return getJdbcTemplate().query (new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection con)
throws SQLException {
PreparedStatement st = con.prepareStatement(query);
st.setString(1, name);
if (logger.isDebugEnabled()) {
logger.debug(st.toString());
}
return st;
}
}, new ResultSetExtractor<Role>() {
@Override
public Role extractData(ResultSet rs) throws SQLException,
DataAccessException {
if (rs.next()) {
return new Role (rs.getString("rolename"), rs.getString("description"));
}
return null;
}});
}