当前位置: 移动技术网 > IT编程>开发语言>Java > jsp与sql语句的混合使用示例

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

2017年12月12日  | 移动技术网IT编程  | 我要评论

皇色 小说,信息港,王波 叙利亚

话不多说,直接上例子
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>

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网