1

菜鸟求教 javaweb如何显示服务器内的数据

如下代码:

 <%@ page language="java" import="java.util.*" %>
<%@ page import="java.sql.*" %>


<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
</head>
<body>
    <%
        String id=request.getParameter("stu_id").toString();

        String db_driver="com.mysql.jdbc.Driver";
        String db_url="jdbc:mysql://127.0.0.1:3306/library?user=root&&password=123456";
        int i = 0;

        try{
            //1加载驱动
            Class.forName(db_driver);
            //2构建连接
            Connection conn=DriverManager.getConnection(db_url);
            //3构建执行语句

        String sql = "select *from student where id=?";
        PreparedStatement pstmt;


          pstmt =conn.prepareStatement(sql);
          pstmt.setString(1, id);

          //i = pstmt.executeUpdate();

          ResultSet rs=pstmt.executeQuery();

          String stu_id=rs.getString(1);
          String stu_name=rs.getString(2);
          String stu_pass=rs.getString(3);
          int stu_borrow=rs.getInt(4);

           pstmt.close();
           conn.close();


    }
    catch (SQLException e) {
            e.printStackTrace();
    }

     response.sendRedirect("Manager.jsp");
     %>


</body>
</html>

如何在网页上显示从数据库中获取的 stu_id, stu_name, stu_pass,stu_borrow

查看全部
qq_26432439
qq_26432439
2017/04/15 05:14
  • java
  • html5
  • 数据库
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复