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