网络编程 
首页 > 网络编程 > 浏览文章

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

(编辑:jimmy 日期: 2024/9/21 浏览:3 次 )
话不多说,直接上例子
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>
上一篇:jsp获取action传来的session和session清空以及判断
下一篇:jsp文件绝对路径的设置方法
一句话新闻
微软与英特尔等合作伙伴联合定义“AI PC”:键盘需配有Copilot物理按键
几个月来,英特尔、微软、AMD和其它厂商都在共同推动“AI PC”的想法,朝着更多的AI功能迈进。在近日,英特尔在台北举行的开发者活动中,也宣布了关于AI PC加速计划、新的PC开发者计划和独立硬件供应商计划。
在此次发布会上,英特尔还发布了全新的全新的酷睿Ultra Meteor Lake NUC开发套件,以及联合微软等合作伙伴联合定义“AI PC”的定义标准。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 SiteMap