我正在尝试更新,但它无法正常工作并抛出此错误:
sql=com.mysql.jdbc.JDBC42PreparedStatement@2b4a207c:update backup.add_event set title ='hhh',eventDesc ='jj',StartTime = '02:00:AM'EndTime = '02:00:AM' ,预算= 234.0,起始日期= '2017年9月1日',结束日期= '2017年9月1日',环境=空 错误=错误:您的SQL语法中有错误;检查与MySQL服务器版本对应的手册,以便在'EndTime = '02:00:AM',Budget = 234.0,StartDate ='2017-09-01',EndDate ='2017-09-01附近使用正确的语法',Envi'在第1行
我试过像一百次检查,认真找不到错误
DBAO.java:
....
public boolean updateEvent(AddEvents myEvent)throws Exception{
try
{
String updateStatement= "update backup.add_event set title=?,eventDesc=?,StartTime=? EndTime=?,Budget=?";
updateStatement = updateStatement+",StartDate=?,EndDate=?,Environment=?";
PreparedStatement prepStmt = con.prepareStatement(updateStatement);
prepStmt.setString(1,myEvent.getTitle());
prepStmt.setString(2,myEvent.getEventDesc());
prepStmt.setString(3,myEvent.getStartTime());
prepStmt.setString(4,myEvent.getEndTime());
prepStmt.setDouble(5,myEvent.getBudget());
prepStmt.setDate(6,(Date) myEvent.getStartDate());
prepStmt.setDate(7,(Date) myEvent.getEndDate());
prepStmt.setString(8,myEvent.getEnvironment());
System.out.println("sql=" +prepStmt.toString());
int status = prepStmt.executeUpdate();
if(status!=0)
{
System.out.println("Record updated");
return true;
}
else
{
return false;
}
}catch(Exception ex)
{
throw new Exception("Error:" +ex.getMessage());
}
}
}
UpdateServlet:
package servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import database.DBAO;
import model.AddEvents;
/**
* Servlet implementation class UpdateServlet
*/
@WebServlet("/UpdateServlet")
public class UpdateServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public UpdateServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//response.getWriter().append("Served at: ").append(request.getContextPath());
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//doGet(request, response);
AddEvents myEvent = new AddEvents();
myEvent.setTitle(request.getParameter("Title"));
myEvent.setEventDesc(request.getParameter("EventDesc"));
myEvent.setStartDate(java.sql.Date.valueOf(request.getParameter("StartDate")));
myEvent.setEndDate(java.sql.Date.valueOf(request.getParameter("EndDate")));
myEvent.setStartTime(request.getParameter("StartTime"));
myEvent.setEndTime(request.getParameter("EndTime"));
//myEvent.setBudget(request.getParameter("Budget"));
myEvent.setBudget(Double.valueOf(request.getParameter("Budget")));
myEvent.setEnvironment(request.getParameter(request.getParameter("Environment")));
try
{
DBAO myDatabase = new DBAO();
boolean status= myDatabase.updateEvent(myEvent);
if(status)
{
HttpSession mysess = request.getSession(true);
mysess.setAttribute("Event_Info", myEvent);
request.getRequestDispatcher("Retrieve.jsp").forward(request, response);
}
else{
request.getRequestDispatcher("Update.jsp").forward(request,response);
}
}
catch(Exception ex)
{
System.out.println("Error="+ex.getMessage());
}
}
}
答案 0 :(得分:0)
你在“StartTime =?EndTime =?”之间缺少一个逗号。