欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jsp與sql語(yǔ)句的混合使用示例

 更新時(shí)間:2014年03月22日 18:04:28   作者:  
這篇文章主要介紹了jsp與sql語(yǔ)句的混合使用,需要的朋友可以參考下
話不多說(shuō),直接上例子
insert
復(fù)制代碼 代碼如下:

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
復(fù)制代碼 代碼如下:

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
復(fù)制代碼 代碼如下:

與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>
<%
}
// 關(guān)閉連接
stmt.close();// 關(guān)閉命令對(duì)象連接
con.close();// 關(guān)閉數(shù)據(jù)庫(kù)連接
} catch (SQLException e) {
e.printStackTrace();
out.println("數(shù)據(jù)庫(kù)連接錯(cuò)誤");
System.exit(0);
}
//數(shù)據(jù)庫(kù)連接完成
%>
</table>

相關(guān)文章

最新評(píng)論