网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的考试资料:

 

标题 jsp与sql语句的混合使用示例
内容
    这篇文章主要介绍了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>
    <%
    }
    // 关闭连接
    stmt.close();// 关闭命令对象连接
    con.close();// 关闭数据库连接
    } catch (SQLException e) {
    e.printStackTrace();
    out.println("数据库连接错误");
    System.exit(0);
    }
    //数据库连接完成
    %>
    </table>
随便看

 

在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/29 1:56:34