展会信息港展会大全

jsp与sql语句的混合使用示例
来源:互联网   发布日期:2016-03-01 10:39:37   浏览:934次  

导读:这篇文章主要介绍了jsp与sql语句的混合使用,需要的朋友可以参考下话不多说,直接上例子insert代码如下:String sql=...

这篇文章主要介绍了jsp与sql语句的混合使用,需要的朋友可以参考下

话不多说,直接上例子

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>

赞助本站

人工智能实验室

相关热词: 开发 编程 android

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港