如何在一个JSP页面执行2个SQL语句?先执行选择再进行删除操作。
<%{Stringh=request.getParameter("hname");dbdbc=newdb();Connectioncon=dbc.getCon();Sta...
<% { String h=request.getParameter("hname");
db dbc = new db();
Connection con = dbc.getCon();
Statement stmt = null;
ResultSet rs = null;
Statement stmt1 = null;
String sql = "";
String str="";
try {
sql = "delete from housedel where hname='"+h+"'";
stmt = con.createStatement();
rs = stmt.executeQuery(sql);//执行查询
while (rs.next()) {//如果记录集不空 访问记录集的每一条记录
String hname = rs.getString("hname");
String addr = rs.getString("addr");
int area = rs.getInt("area");
float price = rs.getFloat("price");
String no = rs.getString("no");
float lowprice = rs.getFloat("lowprice");
String pno = rs.getString("pno");
String category = rs.getString("category");
String towards = rs.getString("towards");
String state = rs.getString("state");
str="insert into house values("+hname+","+addr+","+area+","+price+","+no+","+lowprice+","+pno+","+category+","+towards+","+state+")";
}
stmt.close();
stmt1= con.createStatement();
int result = stmt1.executeUpdate(str);//执行查询
response.setHeader("refresh","2;URL=staff.jsp");
} catch (SQLException e) {
out.println(e.getMessage());
}
}
%>
想做还原操作 删除一个表的一条记录 加入另一张表
报错没有结果集 展开
db dbc = new db();
Connection con = dbc.getCon();
Statement stmt = null;
ResultSet rs = null;
Statement stmt1 = null;
String sql = "";
String str="";
try {
sql = "delete from housedel where hname='"+h+"'";
stmt = con.createStatement();
rs = stmt.executeQuery(sql);//执行查询
while (rs.next()) {//如果记录集不空 访问记录集的每一条记录
String hname = rs.getString("hname");
String addr = rs.getString("addr");
int area = rs.getInt("area");
float price = rs.getFloat("price");
String no = rs.getString("no");
float lowprice = rs.getFloat("lowprice");
String pno = rs.getString("pno");
String category = rs.getString("category");
String towards = rs.getString("towards");
String state = rs.getString("state");
str="insert into house values("+hname+","+addr+","+area+","+price+","+no+","+lowprice+","+pno+","+category+","+towards+","+state+")";
}
stmt.close();
stmt1= con.createStatement();
int result = stmt1.executeUpdate(str);//执行查询
response.setHeader("refresh","2;URL=staff.jsp");
} catch (SQLException e) {
out.println(e.getMessage());
}
}
%>
想做还原操作 删除一个表的一条记录 加入另一张表
报错没有结果集 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询