IDEA使用sql语句查询异常
#这个sql 语句 是获取表的模糊查询 数据总数,在mysql数据库中查出来是5
/ select count(*) from t_student s1,t_clazz c1,t_group t1,t_city c2,t_mark t2 where s1.s_clazz_id=c1.id and t1.g_clazz_id=c1.id and c2.id=s1.s_city_id and t2.m_id=s1.s_mark_id and s1.name like concat('张','%') /
================================================================================
/***
/***
* 模糊查询总数
* @param field 要查询的字段名
* @param obscure 模糊字段
* @return
*/
@Override
public int count(String field, String obscure) {
String sql = "select count(*) from t_student s1,t_clazz c1,t_group t1,t_city c2,t_mark t2 where s1.s_clazz_id=c1.id and t1.g_clazz_id=c1.id and c2.id=s1.s_city_id and t2.m_id=s1.s_mark_id and ? like concat(?,'%')";
try {
PreparedStatement ps = connection.prepareStatement(sql);
ps.setString(1, field);
ps.setString(2, obscure);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getInt("count(*)");
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
return 0;
}
//测试类
public class Text {
public static void main(String[] args) {
StudentDaoImpl studentDao = new StudentDaoImpl();
int count = studentDao.count("s1.name", "张");
**//_测试类里面测出来是怎么0啊**
System.out.println(count);
}
}
问题:为什么在数据库中查到的正确的5,在测试类里面查到的确是0?