我在jsp文件中有这些。但是这些值在mysql表中没有更新。可能是它没有提交。我该如何解决这个问题?
String passc1 = request.getParameter("passc1");
String accid = request.getParameter("accid");
int i = 0;
String sql =
" update customertb "
+ " set passwd = ?"
+ " where acc_no = ?;";
try {
PreparedStatement ps = con.prepareStatement(sql);
ps.setString(1, passc1);
ps.setString(2, accid);
i = ps.executeUpdate();
} catch (Exception e) {
// do something with Exception here. Maybe just throw it up again
} finally {
con.close();
}
堆栈跟踪
Apr 01,2012 11:29:02 PM org.apache.catalina.core.StandardWrapperValve invoke 严重:servlet [jsp]的Servlet.service()在上下文中与path []引发异常[在第81行处理JSP页面/changepwd_done.jsp时发生异常
e.printStackTrace();
} finally {
//con.close();
con.commit();
}
Stacktrace:]有根本原因 java.sql.SQLException:当autocommit = true时,不能调用commit 在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936) 在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:933) 在com.mysql.jdbc.ConnectionImpl.commit(ConnectionImpl.java:1635) 在org.apache.jsp.changepwd_005fdone_jsp._jspService(changepwd_005fdone_jsp.java:160) 在org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:722) 在org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433) 在org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389) 在org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:722) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at or or or or or or or or or or or or or or or or or 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224) 在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169) 在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) 在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) 在org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929) 在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405) 在org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964) at org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:515) at org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:304) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:603) 在java.lang.Thread.run(Thread.java:722)
答案 0 :(得分:4)
捕获SQLException并检查控制台消息:
[...]
try {
PreparedStatement ps = con.prepareStatement(sql);
ps.setString(1, passc1);
ps.setString(2, accid);
i = ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}