同一句SQL语句,在使用普通的Jdbc数据库连接的时候执行可以返回处结果,但是当时用JdbcTemplate时返回处来的结果为空代码如下
未使用JdbcTemplate
String sql = "SELECT * FROM customer WHERE is_delete = 0 AND customer_name = ? " +
"ORDER BY check_in_time DESC LIMIT ?,?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,cName);
pstmt.setInt(2,startItem);
pstmt.setInt(3,pageSize);
使用JdbcTemplate
String sql = "SELECT * FROM customer WHERE is_delete = 0 AND customer_phone = ? " +
"AND room_num LIKE ? ORDER BY check_in_time DESC LIMIT ?,?";
list = template.query(sql, new BeanPropertyRowMapper<Customer>(Customer.class),
recCusPhone, recCusRoNum + "%", startItem, pageSize);
其实问题还是出在配置文件上,也就是编码上,首先出现这种问题是中文,如果换成英文的话就不会出现这种问题了,其实只要在配置文件url后面加上这样一句代码就可以了
?useUnicode=true&characterEncoding=utf8&mysqlEncoding=utf8
网友评论