Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 有人能纠正这个SQL语法异常吗_Java_Mysql - Fatal编程技术网

Java 有人能纠正这个SQL语法异常吗

Java 有人能纠正这个SQL语法异常吗,java,mysql,Java,Mysql,错误:com.mysql.jdbc.exceptions.MySQLSyntaxErrorException:您的SQL语法有错误;查看与MySQL服务器版本对应的手册,以了解第1行“index='2'附近要使用的正确语法 索引是一个关键字,如果将其用作列名,请尝试使用倾斜转义。(`) 索引是一个保留关键字。不要用作列名。。。。 protected void doPost(HttpServletRequest request, HttpServletResponse response) thro

错误:com.mysql.jdbc.exceptions.MySQLSyntaxErrorException:您的SQL语法有错误;查看与MySQL服务器版本对应的手册,以了解第1行“index='2'附近要使用的正确语法


索引
是一个关键字,如果将其用作列名,请尝试使用倾斜转义。(`)


索引是一个保留关键字。不要用作列名。。。。
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
{   
    String index= request.getParameter("Index");
    index=index.trim();

    System.out.println(index);

    PrintWriter out = response.getWriter();
    try 
    {
        Class.forName("com.mysql.jdbc.Driver");
        Connection dbConnection=DriverManager.getConnection("jdbc:mysql://localhost:3306/smb","root","");
        System.out.println(" Connected ");

        PreparedStatement ps=(PreparedStatement) dbConnection.prepareStatement(" select index from books where index=? ");
        System.out.println(" Prepared ");

        try
        {           
            ps.setString(1, index);         
            ResultSet rs = ps.executeQuery();               

            String keysInDb;
            keysInDb="";

            while(rs.next())
            {
                keysInDb=rs.getString(1);
                System.out.println(keysInDb);
            }

            dbConnection.close();

        }
        catch (Exception e) 
        {
            System.out.println("ERROR : "+e);
        }



    }
    catch (Exception e) 
    {
        out.print(e);
    }



}
....
PreparedStatement ps=(PreparedStatement) dbConnection.prepareStatement(" select `index` from books where `index`=? ");
....