(急)关于jsp与mysql访问出现错误

致Great 阿里巴巴 算法实习生  2015-10-30 11:47:00
十月 30, 2015 11:49:01 下午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [jsp] in context with path [/test1] threw exception [An exception occurred processing JSP page /check.jsp at line 21

18: String Birth = "";
19: String Memo = "";
20: operation = (String)request.getParameter("operation");
21: S_no=request.getParameter("S_no").trim();
22: Name=request.getParameter("Name").trim();
23: Sex=request.getParameter("Sex").trim();
24: Politic=request.getParameter("Politic").trim();


Stacktrace:] with root cause
java.lang.NullPointerException
at org.apache.jsp.check_jsp._jspService(check_jsp.java:84)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at encode.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:145)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)


下面是我的代码

<%@ page language="java" contentType="text/html; charset=gb2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.sql.*,java.text.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Insert title here</title>
</head>
<body>
<%
String operation = "";
String S_no = "";
String Name = "";
String Sex = "";
String Politic = "";
String Department = "";
String Come = "";
String Birth = "";
String Memo = "";
operation = (String)request.getParameter("operation");
S_no=request.getParameter("S_no").trim();
Name=request.getParameter("Name").trim();
Sex=request.getParameter("Sex").trim();
Politic=request.getParameter("Politic").trim();
Department=request.getParameter("Department").trim();
Come=request.getParameter("Come").trim();
Birth=request.getParameter("Birth").trim();
Memo=request.getParameter("Memo").trim();
Connection conn=null;
PreparedStatement stmt=null;
String sql=null;
ResultSet rs=null;
String error="false";
try{
//Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
//conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student","sa","sa");
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//conn=DriverManager.getConnection("jdbc:odbc:Student_info; useUnicode=true&characterEncoding=GBK; DatabaseName=studentDB","","");


Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/student","root","miffy1314");
if("add".equals(operation))
{
sql="select * from tb_student where S_no =?";
stmt=conn.prepareStatement(sql);
stmt.setString(1,S_no);
rs=stmt.executeQuery();
Date birth=null;
if(rs.next()==false){
if(Birth.equals("")==true){
Birth="1900-01-01";
}
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
birth=new Date(format.parse(Birth).getTime());
sql="insert into tb_student values(?,?,?,?,?,?,?,?)";
stmt=conn.prepareStatement(sql);
stmt.setString(1,S_no);
stmt.setString(2,Name);
stmt.setString(3,Sex);
stmt.setString(4,Politic);
stmt.setString(5,Department);
stmt.setString(6,Come);
stmt.setDate(7,birth);
stmt.setString(8,Memo);
stmt.executeUpdate();
rs.close();
}
else error="true";
}
if("modify".equals(operation)){
Date birth=null;
if(Birth.equals("")==true){
Birth="1900-01-01";
}
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
birth=new Date(format.parse(Birth).getTime());
sql = "update tb_student set Name=?,Sex=?,Politic=?,Department=?,Come=?,Birth=?,Memo=? where S_no=?";
stmt=conn.prepareStatement(sql);
stmt.setString(1,Name);
stmt.setString(2,Sex);
stmt.setString(3,Politic);
stmt.setString(4,Department);
stmt.setString(5,Come);
stmt.setDate(6,birth);
stmt.setString(7,Memo);
stmt.setString(8,S_no);
stmt.executeUpdate();
}
stmt.close();
conn.close();
}
catch(Exception e)
{
e.printStackTrace();
}finally{
try{if(stmt!=null) stmt.close();
}catch(Exception e){}
try{if(conn!=null) conn.close();
}catch(Exception e){}
}
%>
<form method="post">
<input type="hidden" name="error" value=<%=error%>>
<input type="hidden" name="operation" value=<%=operation%>>
</form>
<script language="javascript" type="text/javascript">
var form=document.forms[0];
if(form.operation.value=="modify"){
form.action="student.jsp";
}
if(form.operation.value=="add")
{
if(form.error.value=="true"){
form.action="update.jsp";
}
else form.action="student.jsp";
}
form.submit();
</script>
</body>
</html>
...全文
67 点赞 收藏 1
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
825609451 2015-10-31
84行空指针异常 看看stmt.setString(5,Come); 看看你的Come是不是为null
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2015-10-30 11:47
社区公告
暂无公告