查无此人-9527

导航

mysql中字段存储不区分大小写

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("登录失败");
    }

posted on 2023-04-11 17:17  查无此人-9527  阅读(68)  评论(0编辑  收藏  举报