MySQL的JDBC UPDATE ERROR - 错误代码1054

时间:2011-10-24 19:23:25

标签: java mysql sql

这是代码

    PreparedStatement res1 = null;
    String insertUser = "INSERT INTO users (uid,firstname,lastname,score) VALUES (" + 
                                            this.getFbUid() + "," + 
                                            this.getFbFirstName() + "," + 
                                            this.getFbLastName() + ",0)";
    System.out.println(insertUser);
    try
    {
        res1 = connection.prepareStatement(insertUser);
        res1.executeUpdate();
        System.out.println("executed query to db with the message" + res1);
    }
    catch(SQLException e)
    {
        System.out.println("setUserInDb: " +e.getMessage());
        System.out.println("error num: " +e.getErrorCode());
    }`

我正在error code 1054

  

尝试插入行“INSERT INTO users(uid,firstname,lastname,score)VALUES(123456,Alon,xyz,0)”时,“字段列表”中的未知列“Alon”

在数据库中,我有users个列varcharuidfirstnamelastnamescore。{ 我做错了什么?

2 个答案:

答案 0 :(得分:0)

Alon似乎或类型varchar应位于'

使用预备语句而不是

答案 1 :(得分:0)

就像Jigar指出的那样,

当你将String值插入表中时,你应该使用单引号或双引号('或')中的值。 例如'你好',“你好”。