Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  Jsp  >  正文 jsp与sql语句怎么混合使用

jsp与sql语句怎么混合使用

发布时间:2015-09-29   编辑:www.jquerycn.cn
本文介绍了jsp与sql语句的混合使用方法,jsp、sql语句混合使用的例子,感兴趣的朋友参考下。

例1,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");
 

例2,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");
 

例3,update
与delete,insert差不多
 
select
 

复制代码 代码示例:
<%
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>

您可能感兴趣的文章:
jsp与sql语句怎么混合使用
JSP 怎么提高数据库访问效率
JSP常见问题
JSP 结构
JSP 简介
php在jsp里面使用的么
JSP 标准标签库(JSTL)
建立JSP操作以提高数据库访问的效率
jsp常见问题二
PHP多久能学会?

关键词: sql语句   
[关闭]