-2
@Override
public List<String> getusers(String role) {
// TODO Auto-generated method stub
String namecount = "SELECT userName FROM users WHERE userName LIKE ?";
role="\"%" + role + "%\"";
List<String> names = jdbcTemplate.query("SELECT userName FROM users where userName like ?", new RowMapper() {
public Object mapRow(ResultSet resultSet, int i) throws SQLException {
return resultSet.getString(1);
}
},role);
System.out.println(names);
return names;
}
我不理解爲什麼我得到這個錯誤條款,可以請一個說哪裏出了問題像春天JDBC
Error message:
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [SELECT userName FROM users userName like ?]; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'like '%blabla%'' at line 1
我不明白爲什麼ia得到那個錯誤 – Ganesh
你的查詢沒有'like'%blabla%'',上面粘貼的代碼是正確的嗎? –
哦,對不起,我粘貼了我的代碼的錯誤部分,我將編輯它 – Ganesh