jsp與sql語句的混合使用示例
更新時間:2014年03月22日 18:04:28 作者:
這篇文章主要介紹了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>
<%
}
// 關(guān)閉連接
stmt.close();// 關(guān)閉命令對象連接
con.close();// 關(guān)閉數(shù)據(jù)庫連接
} catch (SQLException e) {
e.printStackTrace();
out.println("數(shù)據(jù)庫連接錯誤");
System.exit(0);
}
//數(shù)據(jù)庫連接完成
%>
</table>
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)閉命令對象連接
con.close();// 關(guān)閉數(shù)據(jù)庫連接
} catch (SQLException e) {
e.printStackTrace();
out.println("數(shù)據(jù)庫連接錯誤");
System.exit(0);
}
//數(shù)據(jù)庫連接完成
%>
</table>
相關(guān)文章
JSP中實現(xiàn)系統(tǒng)登錄后的退出原理及代碼
首先要在你登錄的頁面的某個地方,寫上一個超級鏈接,讓它鏈接到exit.jsp頁面去,然后新建一個exit.jsp頁面在其body中寫上如下代碼,即可以實現(xiàn)登錄后的退出,感興趣的朋友可以了解下啊,或許對你有所幫助2013-01-01多種方法實現(xiàn)當(dāng)jsp頁面完全加載完成后執(zhí)行一個js函數(shù)
實現(xiàn)jsp頁面完全加載完成后執(zhí)行一個js函數(shù)的方法有很多,在本文就簡單為大家介紹下常用的幾種,感興趣的朋友不要錯過2013-10-10J2EE 開發(fā)購物網(wǎng)站 經(jīng)驗篇 - 建表
J2EE 開發(fā)購物網(wǎng)站 經(jīng)驗篇 - 建表...2006-10-10秒殺系統(tǒng)Web層設(shè)計的實現(xiàn)方法
這篇文章主要介紹了秒殺系統(tǒng)Web層設(shè)計的實現(xiàn)方法的相關(guān)資料,希望通過本文能幫助到大家,讓大家掌握這樣的設(shè)計方式,需要的朋友可以參考下2017-10-10