错误:SQL语法中有错误;检查与MySQL服务器版本对应的手册,以便在**附近使用正确的语法

时间:2022-06-18 00:34:07

I have an error message in Java eclipse. I have a database in MySql and it has colomns String user_name, int id_time, int id_desk, int user_password. I want to insert data with using

我在Java eclipse中有一条错误消息。我在MySql中有一个数据库,它有colomns String user_name,int id_time,int id_desk,int user_password。我想使用使用插入数据

public void reserve(String user_name, int id_time, int id_desk, int user_password){

    try{
        String reserveSql = "INSERT INTO reservation"
                +"VALUES ('" + user_name + "," + id_time + "," + id_desk + "," + user_password + "');";
        stmt.executeUpdate(reserveSql);
    }catch (SQLException ex) {
        System.out.println("Error: " + ex.getMessage());
    }
} 

method.

In database user_name is varchar(45), id_time is int(3), id_desk is int(3) and user_password is int(4)

在数据库中,user_name是varchar(45),id_time是int(3),id_desk是int(3),user_password是int(4)

But in main method when i write

但在我写的主要方法

object.reserve("irem",002,111,1111);

it give me error message that

它给我的错误信息

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''irem,2,111,1111')' at line 1

错误:SQL语法中有错误;查看与您的MySQL服务器版本对应的手册,以便在第1行''irem,2,111,1111')附近使用正确的语法

how can i fix it? Thanks for helping

我该怎么办呢?谢谢你的帮助

1 个解决方案

#1


1  

You forgot spaces and " ' "- around the strings, but you have to "Learn to use parameterized queries" like xQbert says...

你忘了空格和“'” - 在字符串周围,但你必须“学习使用参数化查询”,如xQbert说...

#1


1  

You forgot spaces and " ' "- around the strings, but you have to "Learn to use parameterized queries" like xQbert says...

你忘了空格和“'” - 在字符串周围,但你必须“学习使用参数化查询”,如xQbert说...