简体   繁体   English

数据截断:截断了错误的DOUBLE值:

[英]Data truncation: Truncated incorrect DOUBLE value:

I have been trying to solve this for hours and I have no idea why this is happening. 我已经尝试解决了几个小时,但我不知道为什么会这样。 I keep on getting this error when trying to update one of my "Employees" with my GUI that I made. 尝试使用我制作的GUI更新我的“雇员”之一时,我不断收到此错误。

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: 'test'

Whenever I click an employee in my TableView, and then change the field of something, I would get that. 每当我在TableView中单击某个员工,然后更改某些字段时,我都会明白这一点。 Here is a picture of my GUI: 这是我的GUI的图片:

员工记录

Nothing in my data table is a DOUBLE, they all are like this: 我的数据表中没有任何东西是双的,它们都是这样的:

mysql数据表

I have googled everywhere and it all says it relates to syntax for my SQL query but that looks fine so I do not know why. 我到处都有Google搜索,都说它与我的SQL查询的语法有关,但这看起来还不错,所以我不知道为什么。

Here is the code for my Update button: 这是我的“更新”按钮的代码:

public void handleUpdateEmployee(ActionEvent event) {
    String sql = "UPDATE employees set firstName = ?, lastName = ?, gender = ?, age = ?, position = ?, image = ? where employeeNum =?";
    try {
        Integer employeeNum = Integer.valueOf(employeeNumField.getText());
        String firstName = firstNameField.getText();
        String lastName = lastNameField.getText();
        String gender = genderField.getText();
        Integer age = Integer.valueOf(ageField.getText());
        String position = positionField.getText();
        String image = imageField.getText();

        pst = con.prepareStatement(sql);
        pst.setInt(1, employeeNum);
        pst.setString(2, firstName);
        pst.setString(3, lastName);
        pst.setString(4, gender);
        pst.setInt(5, age);
        pst.setString(6, position);
        pst.setString(7, image);

        pst.executeUpdate();
        loadEmployeeData();

    } catch (SQLException e) {
        e.printStackTrace();
    }
}

Would appreciate any help and if you need any more details, let me know! 感谢您的帮助,如果您需要更多详细信息,请告诉我!

You bound your query parameters in the wrong order. 您以错误的顺序绑定了查询参数。 Look closely at the statement and then the updated code which follows: 仔细查看该语句,然后仔细查看下面的更新代码:

String sql = "UPDATE employees set firstName = ?, lastName = ?, gender = ?, ";
sql += "age = ?, position = ?, image = ? where employeeNum =?";

pst.setString(1, firstName);  // first parameter (?) in statement
pst.setString(2, lastName);
pst.setString(3, gender);
pst.setInt(4, age);
pst.setString(5, position);
pst.setString(6, image);
pst.setInt(7, employeeNum);   // LAST parameter (?) in statement

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM