JSP连数据库时出错
在关闭连接的时候一直出错, 请大侠指点。。。。
org.apache.jasper.JasperException: An exception occurred processing JSP page /news/login.jsp at line 26
23: out.print("用户名或密码错误!");
24: }catch(Exception ce){System.out.print(ce.toString());}
25: finally{
26: con.close();
27: pst.close();
28: rst.close();
29: }
原代码如下:
<%@ page contentType="text/html;charset=GBK"%>
<%@ page import="java.sql.*"%>
<%
String username,userpwd;
username=request.getParameter("username");
userpwd=request.getParameter("userpwd");
Connection con=null;
PreparedStatement pst=null;
ResultSet rst=null;
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con=DriverManager.getConnection("jdbc:sqlserver://localhost;database=News","yjw757174266","yejianwen");
pst=con.prepareStatement("select * from usertabel where username=? and userpwd=?");
pst.setString(1,username);
pst.setString(2,userpwd);
rst=pst.executeQuery();
if(rst.next()){
session.setAttribute("username",username);
session.setAttribute("loged","true");
response.sendRedirect("main.jsp");
}
else
out.print("用户名或密码错误!");
}catch(Exception ce){System.out.print(ce.toString());}
finally{
con.close();
pst.close();
rst.close();
}
%>
感激不尽。。。。
------解决方案--------------------
if(null != con && !con.isColse())
con.close();
------解决方案--------------------
finally{
con.close();
pst.close();
rst.close();
}
你最后都没有判断就关闭。如果已经关闭了再执行关闭的操作不是会报错么?
我的异常网推荐解决方案:An exception occurred processing JSP page,http://www.aiyiweb.com/j2se/33144.html