【发布时间】:2016-06-12 14:34:20
【问题描述】:
我创建了项目servlet 和jsp。我正在使用数据库phpmyadmin。我遇到了显示数据库产品的语法错误。在 Eclipse EE 控制台中返回以下错误。我没有解决问题。任何帮助将不胜感激。
com.mysql.jdbc.exceptions.jdbc4.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 'order
(id,idUser,order,total) values (default,'1','flower','83.8883')' at
line 1
Servlet 类:
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
String idUser = req.getParameter("idUser");
System.out.println(idUser);
String order = req.getParameter("order");
System.out.println(order);
String total = req.getParameter("total");
System.out.println(total);
try {
Class.forName("com.mysql.jdbc.Driver");
Connection cnx = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/shop","root","");
PreparedStatement pr = (PreparedStatement) cnx.prepareStatement(
"insert into order (id,idUser,order,total) values (default,?,?,?)"
);
pr.setString(1,idUser);
pr.setString(2,order );
pr.setString(3, total);
pr.executeUpdate();
pr.close();
resp.sendRedirect("Home");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
【问题讨论】:
-
请发布正在触发的实际查询