Looks like I m missing something in this statement. Trying to Encrypt the password before that goes in DB. And, using following String.
String Sql = "INSERT INTO virtual_users"
+"(domain_id, password, email) VALUES"
+"(?,ENCRYPT(?, CONCAT('$6$', SUBSTRING(SHA(RAND()), -16))),?)";
Is there anything wrong with above ENCRYPT?
Complete Code for reference.
public void AddMail(MailUsers mAC) {
String Sql = "INSERT INTO virtual_users"
+"(domain_id, password, email) VALUES"
+"(?,ENCRYPT(?, CONCAT('$6$', SUBSTRING(SHA(RAND()), -16))),?)";
PreparedStatement ps = null;
try {
ps = DBUtils.getPreparedStatement(Sql);
ps.setInt(1, mAC.getDomain_id());
ps.setString(2, mAC.getPassword());
ps.setString(3, mAC.getEmail());
System.out.println(ps);
ps.executeUpdate();
} catch (ClassNotFoundException | SQLException ex) {
Logger.getLogger(DataAccess.class.getName()).log(Level.SEVERE, null, ex);
System.out.println(ps);
}
}
ERROR
com.mysql.jdbc.JDBC42PreparedStatement@1c9aab0a: INSERT INTO virtual_users(domain_id, password, email) VALUES(1,ENCRYPT('asdfasdf', CONCAT('$6$', SUBSTRING(SHA(RAND()), -16))),'tink@in.in') Severe: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'password' cannot be nul