错误MysqlDataTruncation

时间:2015-11-21 10:32:21

标签: java mysql

我在尝试插入数据库时​​遇到以下错误。

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'password' at row 1

我在执行此方法后得到它:

    @Override
public void create(int id, int personal, String password, String firstName, String lastName, String role,
        String email, String startDate, int teamId) throws ParseException {
    SimpleDateFormat from = new SimpleDateFormat("dd/MM/yyyy");
    SimpleDateFormat to = new SimpleDateFormat("yyyy-MM-dd");
    Date dateSQL = (Date) from.parse(startDate); // 01/02/2014
    String mysqlString = to.format(dateSQL); // 2014-02-01
    BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
    String hashedPassword = passwordEncoder.encode(password); // hashed
                                                                // password
    String SQL = "insert into Users (id_user, personal_number, password,first_name,last_name,role,email,start_date,Teams_id_team) values (?, ?, ?,?,?,?,?,?,?)";
    jdbcTemplateObject.update(SQL, id, personal, hashedPassword, firstName, lastName, role, email, mysqlString,
            teamId);
    return;
}

在DB中我有列密码,其类型为VARCHAR(80),hashedPassword长度为60个字符。你能告诉我这里有什么问题吗?

修改

这是我的表:

    CREATE TABLE IF NOT EXISTS `wirecard`.`users` (
    `id_user` INT NOT NULL AUTO_INCREMENT,
    `personal_number` INT NOT NULL,
    `password` LONGTEXT NOT NULL,
    `role` VARCHAR(45) NOT NULL,
    `first_name` VARCHAR(45) NOT NULL,
    `last_name` VARCHAR(45) NOT NULL,
    `email` VARCHAR(45) NOT NULL,
    `start_date` DATE NOT NULL,
    `Teams_id_team` INT NULL,
     PRIMARY KEY (`id_user`),
     UNIQUE INDEX `id_user_UNIQUE` (`id_user` ASC),
    UNIQUE INDEX `personal_number_UNIQUE` (`personal_number` ASC))

0 个答案:

没有答案