jsp新手求助:多个结果集resultset嵌套出现结果集关闭怎么改 20
publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletE...
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
HttpSession session = request.getSession();
String ServeNo = (session.getAttribute("ServeNo")).toString();
if(request.getParameter("Submit")!=null){
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url="jdbc:sqlserver://localhost:1433; DatabaseName=yidong";
Connection con=DriverManager.getConnection(url,"sa","chenjunyan");
Statement stmt=con.createStatement();
Statement stmte=con.createStatement();
PreparedStatement pstmt;
String sql="select * from Refund_inf where ServeNo='"+ServeNo+"'";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
String sql2="select * from Prestore_inf where ServeNo='"+ServeNo+"'";
ResultSet rs2=stmte.executeQuery(sql2);
while(rs2.next()){
if(rs.getString(2)==rs2.getString(2)){
int rest=rs.getInt(6);
String rest2=Integer.toString(rest);
String sql3="update Prestore_inf set CurrentBalance='"+rest2+"',RefundAmount='"+rest2+"' where ServeNo='"+ServeNo+"'and PreProject='"+rs2.getString(2)+"'";
String sql4="delete from Prestore_inf where ServeNo='"+ServeNo+"'and PreProject='"+rs.getString(2)+"'";
if(rest==0){
stmte.executeUpdate(sql4);
System.out.println("预存表删除成功!");
}else if(rest>0){
pstmt = con.prepareStatement(sql3);
pstmt.executeUpdate();
System.out.println("预存表修改成功!");
}
}
}
rs2.close();
String sql5="truncate table Refund_inf";
stmt.executeUpdate(sql5);
System.out.println("提交成功!");
}
rs.close();
stmt.close();
con.close();
request.setAttribute("sign", ServeNo);
request.getRequestDispatcher("/fee.jsp").forward(request, response);
}catch(Exception e){
e.printStackTrace();}
} 展开
throws ServletException, IOException {
response.setContentType("text/html");
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
HttpSession session = request.getSession();
String ServeNo = (session.getAttribute("ServeNo")).toString();
if(request.getParameter("Submit")!=null){
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url="jdbc:sqlserver://localhost:1433; DatabaseName=yidong";
Connection con=DriverManager.getConnection(url,"sa","chenjunyan");
Statement stmt=con.createStatement();
Statement stmte=con.createStatement();
PreparedStatement pstmt;
String sql="select * from Refund_inf where ServeNo='"+ServeNo+"'";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
String sql2="select * from Prestore_inf where ServeNo='"+ServeNo+"'";
ResultSet rs2=stmte.executeQuery(sql2);
while(rs2.next()){
if(rs.getString(2)==rs2.getString(2)){
int rest=rs.getInt(6);
String rest2=Integer.toString(rest);
String sql3="update Prestore_inf set CurrentBalance='"+rest2+"',RefundAmount='"+rest2+"' where ServeNo='"+ServeNo+"'and PreProject='"+rs2.getString(2)+"'";
String sql4="delete from Prestore_inf where ServeNo='"+ServeNo+"'and PreProject='"+rs.getString(2)+"'";
if(rest==0){
stmte.executeUpdate(sql4);
System.out.println("预存表删除成功!");
}else if(rest>0){
pstmt = con.prepareStatement(sql3);
pstmt.executeUpdate();
System.out.println("预存表修改成功!");
}
}
}
rs2.close();
String sql5="truncate table Refund_inf";
stmt.executeUpdate(sql5);
System.out.println("提交成功!");
}
rs.close();
stmt.close();
con.close();
request.setAttribute("sign", ServeNo);
request.getRequestDispatcher("/fee.jsp").forward(request, response);
}catch(Exception e){
e.printStackTrace();}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询