zl程序教程

您现在的位置是:首页 >  后端

当前栏目

jsp与sql语句的混合使用示例

JSPSQL 使用 示例 语句 混合
2023-06-13 09:15:20 时间
话不多说,直接上例子
insert
复制代码代码如下:

Stringsql="insertintoallordervalues(""+orderid+"",""+bookid+"",""+amount+"",""+username+"")";
intresult=stmt.executeUpdate(sql);
if(result==1)
response.sendRedirect("index.jsp");
else
response.sendRedirect("detail.jsp");


delete
复制代码代码如下:

Stringcondition="deletefromallorderwhereid=""+orderid+""";
intresult=stmt.executeUpdate(condition);

if(result==1)
response.sendRedirect("index.jsp");
else
out.println("shopCar.jsp");


update
复制代码代码如下:
与delete,insert差不多

select
[code]
<%
while(rs.next()){
Stringamount=rs.getString("amount");
Stringorderid=rs.getString("id");
Stringbookname=rs.getString("name");
Stringprice=rs.getString("price");
Stringpicture=rs.getString("pic");

//out.println("\tshuliang"+amount);
%>
<tr><td><%=orderid%></td><td><%=picture%></td><td><%=bookname%></td><td><%=price%></td><td><%=amount%></td><td><table><tr><td><inputtype="button"value="删除"onclick="window.location.href="delete.jsp?orderid=<%=orderid%>""></td></tr></table></td></tr>
<%
}
//关闭连接
stmt.close();//关闭命令对象连接
con.close();//关闭数据库连接
}catch(SQLExceptione){
e.printStackTrace();
out.println("数据库连接错误");
System.exit(0);
}
//数据库连接完成
%>
</table>