当前位置: 代码迷 >> J2EE >> 结果报错:严重: Servlet.service() for servlet jsp threw exception
  详细解决方案

结果报错:严重: Servlet.service() for servlet jsp threw exception

热度:642   发布时间:2016-04-22 03:45:32.0
关于SQL连接
我的代码是:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%
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 'delete.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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

  </head>
  
  <body>
  <form action="" method="get">
  选择删除的方式: <label>
  <input type="radio" name="deltype" value="按读者编号删除" />
  按读者编号删除</label><label>
  <input type="radio" name="deltype" value="按姓名删除" />按姓名删除
  </label>
  <label> <input type="text" name="delinfo" />
  </label><label>
  <input type="submit" name="Submit" value="提交删除" />
  </label>
  <td class="STYLE3"><div align="right"><a href="main.jsp" class="STYLE4 STYLE1"><kbd>返回首页</kbd></a></div></td>
</form> <% 
  String deltype = request.getParameter("deltype");
try{
byte d[] = deltype.getBytes("ISO-8859-1");
deltype = new String(d);}
catch(Exception e){}
String delinfo=request.getParameter("delinfo");
try{ byte b[]=delinfo.getBytes("ISO-8859-1");
delinfo=new String(b);}
catch(Exception e){}
if(deltype!=null&&delinfo!=null){
  Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String strConn= "jdbc:sqlserver://localhost;databaseName=zc;user=sa;password=123";
Connection conn= DriverManager.getConnection(strConn);  
Statement stmt=conn.createStatement();;
String userid="按读者编号删除";
String username ="按姓名删除";
String a=userid.trim();
String b=deltype.trim();
if((userid.trim()).equals(deltype.trim())){ 
String sql1 ="delete from reader where 读者编号='"+delinfo+"'"; 
int i1 = stmt.executeUpdate(sql1);
out.print("删除成功!!!");}
if((username.trim()).equals(deltype.trim())){
String sql2 ="delete from reader where 读者姓名='"+delinfo+"'"; 
int i2 = stmt.executeUpdate(sql2);
out.print("删除成功!!!");}}%>
  </body>
</html>
结果报错:严重: Servlet.service() for servlet jsp threw exception
com.microsoft.sqlserver.jdbc.SQLServerException: 该语句已关闭。
请求高人指点

------解决方案--------------------
你把倒数第六行开始的
if((username.trim()).equals(deltype.trim())){
String sql2 ="delete from reader where 读者姓名='"+delinfo+"'";
int i2 = stmt.executeUpdate(sql2);
out.print("删除成功!!!");}}
  相关解决方案