求教我下面这段简单的jsp程序为什么会报错ResultSet is closed,而且该段程序存不存在内存泄露的问题? 50
<body><%request.setCharacterEncoding("UTF-8");Stringnumber=request.getParameter("numb...
<body>
<%
request.setCharacterEncoding("UTF-8");
String number=request.getParameter("number_");
String hnumber=request.getParameter("hnumber_");
String confession=request.getParameter("confession_");
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:look_back";
conn=DriverManager.getConnection(url,"sa","k19000531");
stmt=conn.createStatement();
rs=stmt.executeQuery("select * from love where number='"+number+"'");
if(rs.next()){
request.setAttribute("errorMsg","亲,您已经告白过了,ta会收到您的心意的......");
request.getRequestDispatcher("confe.jsp").forward(request, response);
}
else{
stmt.execute("insert into love (number,hnumber,confession,time) values ('"+number+"','"+hnumber+"','"+confession+"',SYSDATETIME())");
request.setAttribute("errorMsg","亲,您的告白真感人,祝您成功!");
request.getRequestDispatcher("confe.jsp").forward(request, response);
}
}
catch (ClassNotFoundException e){
e.printStackTrace();
}
catch (SQLException e){
e.printStackTrace();
}finally{
try{
if(rs!=null){
rs.close();}
if(stmt!=null){
stmt.close();}
if(conn!=null){
conn.close();}}
catch (SQLException e){
e.printStackTrace();}
}
%>
</body> 展开
<%
request.setCharacterEncoding("UTF-8");
String number=request.getParameter("number_");
String hnumber=request.getParameter("hnumber_");
String confession=request.getParameter("confession_");
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:look_back";
conn=DriverManager.getConnection(url,"sa","k19000531");
stmt=conn.createStatement();
rs=stmt.executeQuery("select * from love where number='"+number+"'");
if(rs.next()){
request.setAttribute("errorMsg","亲,您已经告白过了,ta会收到您的心意的......");
request.getRequestDispatcher("confe.jsp").forward(request, response);
}
else{
stmt.execute("insert into love (number,hnumber,confession,time) values ('"+number+"','"+hnumber+"','"+confession+"',SYSDATETIME())");
request.setAttribute("errorMsg","亲,您的告白真感人,祝您成功!");
request.getRequestDispatcher("confe.jsp").forward(request, response);
}
}
catch (ClassNotFoundException e){
e.printStackTrace();
}
catch (SQLException e){
e.printStackTrace();
}finally{
try{
if(rs!=null){
rs.close();}
if(stmt!=null){
stmt.close();}
if(conn!=null){
conn.close();}}
catch (SQLException e){
e.printStackTrace();}
}
%>
</body> 展开
2个回答
展开全部
你一个Statement 用于查询和插入,而resultset只关闭一次,当然会错。。。
每次执行的sql语句都不一样,导致PreparedStatement对象不同
每次执行的sql语句都不一样,导致PreparedStatement对象不同
更多追问追答
追问
PreparedStatement我就没有初始化啊
追答
打错字了
你的stmt=conn.createStatement();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询