当前位置:主页 > 查看内容

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

发布时间:2021-06-15 00:00| 位朋友查看

简介:话不多说,直接上例子 insert 复制代码 代码如下: String sql="insert into allorder values('" + orderid + "','" + bookid +"','" + amount + "','" + username + "')"; int result=stmt.executeUpdate(sql); if(result==1) response.sendRedirect("index.……
话不多说,直接上例子
insert
复制代码 代码如下:

String sql="insert into allorder values('" + orderid + "','" + bookid +"','" + amount + "','" + username + "')";
int result=stmt.executeUpdate(sql);
if(result==1)
response.sendRedirect("index.jsp");
else
response.sendRedirect("detail.jsp");


delete
复制代码 代码如下:

String condition="delete from allorder where id='"+ orderid+ "'";
int result=stmt.executeUpdate(condition);

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


update
复制代码 代码如下:

与delete,insert差不多

select
[code]
<%
while (rs.next()){
String amount=rs.getString("amount");
String orderid=rs.getString("id");
String bookname=rs.getString("name");
String price=rs.getString("price");
String picture=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><input type="button" value="删除" onclick="window.location.href='delete.jsp?orderid=<%=orderid %>'"></td></tr></table></td></tr>
<%
}
// 关闭连接
stmt.close();// 关闭命令对象连接
con.close();// 关闭数据库连接
} catch (SQLException e) {
e.printStackTrace();
out.println("数据库连接错误");
System.exit(0);
}
//数据库连接完成
%>
</table>

本文转载自网络,原文链接:https://m.jb51.net/article/48371.htm
本站部分内容转载于网络,版权归原作者所有,转载之目的在于传播更多优秀技术内容,如有侵权请联系QQ/微信:153890879删除,谢谢!

推荐图文


随机推荐