mysql中查询时,遇到字段不区分大小写的情况,大小写都能取到值
// sql语句中"select * from tab_user where binary username=? and password = ?"; binary 可以做到区分大小写
// MySQL中默认字段是不区分大小写的,如果要完成区分大小写的功能,在设计时要注意字符集的选择
String sql = "select * from tab_user where binary username=? and password = ?";
String username = "jerry";
String password = "123456";
PreparedStatement preparedStatement = JDBCUtils.getPreparedStatement(sql);
preparedStatement.setString(1,username);
preparedStatement.setString(2,password);
ResultSet resultSet = preparedStatement.executeQuery();
if (resultSet.next()){
System.out.println("登录成功");
}else {
System.out.println("登录失败");
}