我正在这样做:
String columns = "UserHash,EMail,Name,Gender,BirthYear,Birthday,MaritalStatus,UserID,ReferralUser,Likes";
String sql = "INSERT INTO Users ("+ columns+") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
byte[] bytesOfUserHash = user.getId().getBytes("UTF-8");
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] userHash = md.digest(bytesOfUserHash);
stmt = con.prepareStatement(sql);
stmt.setBytes(1,userHash);
stmt.setString(2, user.getEmail());
stmt.setString(3, user.getName());
stmt.setInt(4, user.getGender().value());
stmt.setString(5, birthday.split("-")[0]);
stmt.setString(6, birthday);
stmt.setInt(7, user.getRelationshipStatus().value());
stmt.setString(8, user.getId());
stmt.setString(9, referraluser);
stmt.setString(10, likesjson);
stmt.executeUpdate();
正在插入除 之外的所有值userHash
,因此查询成功。我应该检查什么?
另外,请注意我现在只是对用户 ID 进行哈希处理,但我想对用户 ID + 进行哈希处理CURRENT_TIMESTAMP
。
更新: 作为健全性检查,我只是尝试将一个字符串扔到 UserHash 列中,因为它是 VARCHAR(45) 类型的,但这也不起作用。与 MD5 问题无关,显然有些问题。