String requiredKeyword = request.getParameter("KeyWord");
String textBookCode = request.getParameter("BookCode");
String pageNumbers= request.getParameter("PageNumbers");
String definition = request.getParameter("Definition");
PrintWriter show = response.getWriter();
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection dbConnection=DriverManager.getConnection("jdbc:mysql://localhost:3306/main_data","root","");
System.out.println(" Connection Created Successfully ");
PreparedStatement prepSt =(PreparedStatement) dbConnection.prepareStatement(" insert into 'keys'(requiredKeyword,noOfPages,textBookCode,pageNumbers,definition) values(?,?,?,?,?) ");
System.out.println(" Statement Prepared ");
int num=1,i=0;
prepSt.setString(1,requiredKeyword);
prepSt.setInt(2,num);
prepSt.setString(3,textBookCode);
prepSt.setString(4,pageNumbers);
prepSt.setString(5,definition);
try
{
i= prepSt.executeUpdate();
System.out.println(" Executed ");
}
catch(Exception e)
{
show.println(e);
}
if(i>0)
show.println(" Inserted Successfully ");
dbConnection.close();
}
catch (Exception e)
{
show.print(e);
}
ERROR : com.mysql.jdbc.exceptions.MySQLSyntaxErrorException:
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
''keys'(requiredKeyword,noOfPages,textBookCode,pageNumbers,definition) values('da' at line 1
1 个解决方案
#1
0
You're using standard quotes instead of backticks for escaping the MySql reserved word KEYS
. Change the table name to any non-reserved word so that the quotes can be removed.
您使用的是标准引号,而不是用于转义MySql保留字键的回溯。将表名更改为任何非保留字,以便删除引号。
#1
0
You're using standard quotes instead of backticks for escaping the MySql reserved word KEYS
. Change the table name to any non-reserved word so that the quotes can be removed.
您使用的是标准引号,而不是用于转义MySql保留字键的回溯。将表名更改为任何非保留字,以便删除引号。