jsp與sql語句的混合使用示例
來源:易賢網(wǎng) 閱讀:936 次 日期:2015-01-27 15:32:32
溫馨提示:易賢網(wǎng)小編為您整理了“jsp與sql語句的混合使用示例”,方便廣大網(wǎng)友查閱!

這篇文章主要介紹了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>

更多信息請查看IT技術(shù)專欄

更多信息請查看網(wǎng)絡(luò)編程
易賢網(wǎng)手機網(wǎng)站地址:jsp與sql語句的混合使用示例

2025國考·省考課程試聽報名

  • 報班類型
  • 姓名
  • 手機號
  • 驗證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)