我正在使用 mysql 数据库和工作台、Eclipse IDE 和 Tomcat 服务器。我正在将 MVC 模型用于 Web 服务。在 HTML 表单中,当我提供用户名和密码时,会显示用户的所有详细信息,当我尝试更新该用户的详细信息时,它允许我更改网页上的详细信息。但是当我提交更新的详细信息表单时,它会显示以下异常,并且数据库中的详细信息未更新。
标题 1
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'Sapan' in 'where clause'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4187)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4119)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2815)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2375)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2359)
at com.dao.CustomerDAO.updateProduct(CustomerDAO.java:145)
at com.dao.UpdateServlet.doPost(UpdateServlet.java:81)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:680
我不知道问题出在哪里,但是当我尝试首先检索数据时,它会出现任何错误。我的数据库中还有一个用户名“Sapan”。更新数据库的方法在这里。
标题 2
公共类 CustomerDAO 扩展 BaseDAO{
public boolean updateProduct(Login login){
try {
BaseDAO baseDAO = new BaseDAO();
Connection c = baseDAO.getConnection();
String query = "update test.Customer set City=? ,State=? ,PhoneNumber=? ,Email=? ,Address=? ,ZipCode=? where LoginId="+login.getLoginId();
PreparedStatement preparedStatement = c.prepareStatement(query);
preparedStatement.setString(1, login.getCity());
preparedStatement.setString(2, login.getState());
preparedStatement.setString(3, login.getCellnumber());
preparedStatement.setString(4, login.getEmail());
preparedStatement.setString(5, login.getAddress());
preparedStatement.setInt(6, login.getZipcode());
int i = preparedStatement.executeUpdate();
if (i == 1) {
System.out.println("Record updated successfully.");
}
} catch(Exception e) {
e.printStackTrace();
}
return true;
}
}
请帮我找出问题所在。先感谢您。