准备好的SQL语句无效

时间:2015-12-17 00:37:31

标签: java mysql sql-server jsp

我无法弄清楚这一点,并在10小时内到期。如果有人怜惜请帮助。

基本上我试图在名为Appointments的访问表中插入数据。但是每次我都会收到不正确的sql语法错误。我已经浏览了很多sql的例子,这似乎是正确的,我无法解决这个问题。代码和堆栈跟踪如下。错误行表示为第27行或statement.executeupdate()行。我试图在JSP中执行此操作。

<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Dentist", "", "");

String query = "INSERT INTO Appointments(First_Name, Last_Name, Address, Phone_Number, Procedure, Appointment_Date, Health_Insurance, Health_Concerns, Age, Emergency_Contact, Cost) VALUES(?,?,?,?,?,?,?,?,?,?,?)";
java.sql.PreparedStatement statement = connection.prepareStatement(query);

statement.setString(1, request.getParameter("First_name"));
statement.setString(2, request.getParameter("Last_Name"));
statement.setString(3, request.getParameter("Address"));
statement.setString(4, request.getParameter("PhoneNumber"));
statement.setString(5, request.getParameter("Procedure"));
statement.setString(6, request.getParameter("Appointment_Date"));
statement.setString(7, request.getParameter("Health_Insurance"));
statement.setString(8, request.getParameter("Health_Concerns"));
statement.setString(9, request.getParameter("Age"));
statement.setString(10, request.getParameter("Emergency_Contact"));
statement.setString(11, request.getParameter("Cost"));

statement.executeUpdate(query);
connection.close();
response.sendRedirect("ShowData.jsp");
%>

堆栈追踪:

  

2015年12月16日下午7:38:24 org.apache.catalina.core.StandardWrapperValve   调用SEVERE:servlet jsp的Servlet.service()抛出异常   java.sql.SQLException:[Microsoft] [ODBC Microsoft Access驱动程序]   INSERT INTO语句中的语法错误。在   sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6964)at at   sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7121)at at   sun.jdbc.odbc.JdbcOdbc.SQLExecute(JdbcOdbc.java:3156)at at   sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(JdbcOdbcPreparedStatement.java:215)     在   sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdate(JdbcOdbcPreparedStatement.java:137)     在   org.apache.jsp.FinalProject.ProcessInsert_jsp._jspService(ProcessInsert_jsp.java:80)     在org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:803)at   org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)     在   org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)     在org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:803)at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)     在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)     在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)     在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)     在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)     在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)     在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)     在   org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:856)     在   org.apache.coyote.http11.Http11AprProtocol $ Http11ConnectionHandler.process(Http11AprProtocol.java:565)     在   org.apache.tomcat.util.net.AprEndpoint $ Worker.run(AprEndpoint.java:1509)     在java.lang.Thread.run(Thread.java:745)

1 个答案:

答案 0 :(得分:3)

已为PreparedStatement定义了查询。取代

statement.executeUpdate(query);

statement.executeUpdate();