连接数据库时添加用户信息功能可以实现,修改就不能实现了
HTTP Status 500 - An exception occurred processing JSP page /doxiugai.jsp at line 45
type Exception report
message An exception occurred processing JSP page /doxiugai.jsp at line 45
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /doxiugai.jsp at line 45
42: tmt.setString(3, c);
43: tmt.setString(4, d);
44: tmt.setString(5, id);
45: int rst=tmt.executeUpdate();
46: if (rst!= 0){
47: out.println("<script type='text/javascript'>alert('鐢ㄦ埛淇敼鎴愬姛锛�);window.location.href='123456.jsp';</script>");
48: }
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
javax.servlet.ServletException: 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 'add=null, num=null, js=null WHERE id='2'' at line 1
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:912)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)
org.apache.jsp.doxiugai_jsp._jspService(doxiugai_jsp.java:128)
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:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
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 'add=null, num=null, js=null WHERE id='2'' at line 1
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java.lang.reflect.Constructor.newInstance(Constructor.java:526)
com.mysql.jdbc.Util.handleNewInstance(Util.java:403)
com.mysql.jdbc.Util.getInstance(Util.java:386)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:944)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3933)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3869)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2675)
com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2465)
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1915)
com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2136)
com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2070)
com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5187)
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2055)
org.apache.jsp.doxiugai_jsp._jspService(doxiugai_jsp.java:114)
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:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.30 logs.
这是实现修改页面的代码
<%@ page language="java" import="java.util.*,java.sql.*,java.net.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'doxiugai.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<%
request.setCharacterEncoding("utf-8");
String a = request.getParameter("name");
String b = request.getParameter("add");
String c = request.getParameter("num");
String d = request.getParameter("js");
String id = (String) session.getAttribute("id");
Class.forName("com.mysql.jdbc.Driver");//加载驱动
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/jz?useSSL=false","root","root");
PreparedStatement pStmt=conn.prepareStatement("select * from yg where id=?");
pStmt.setString(1, id);
ResultSet rs = pStmt.executeQuery();
PreparedStatement tmt = conn.prepareStatement("update yg set name=?,add=?, num=?, js=? WHERE id=?");
tmt.setString(1, a);
tmt.setString(2, b);
tmt.setString(3, c);
tmt.setString(4, d);
tmt.setString(5, id);
int rst=tmt.executeUpdate();
if (rst!= 0){
out.println("<script type='text/javascript'>alert('用户修改成功!');window.location.href='123456.jsp';</script>");
}
%>
</body>
</html>