如何在JSP页面显示Oracle数据库内容

来源:互联网 发布:淘宝支付宝账号怎么改 编辑:程序博客网 时间:2024/05/28 09:31
<span style="font-size:12px;">
<span style="font-size:14px;">
<%@ page language="java" import="java.sql.*,java.io.*,java.util.*"%>  
<%@ page contentType="text/html;charset=utf-8"%> 
<%@ page import="com.oracle.enjoyshop.base.ConnectionFactory" %>   /*引用数据库连接类*/
<%@ page import="com.oracle.enjoyshop.util.JDBCUtil" %>    /*引用资源关闭类*/



<html>
  <head>
    
    <title>从数据库中的某个表拿到该表所有的数据</title>
    
    <style type="text/css">  
table {  
    border: 2px #CCCCCC solid;  
    width: 360px;  
}  
  
td,th {  
    height: 30px;  
    border: #CCCCCC 1px solid;  
}  
</style> 


  </head>
  
  <body>
      
      <%
               Connection conn = null;
Statement stmt = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
conn = ConnectionFactory.getConnection();
String findSQL = "select u_id,u_name,u_pwd,u_tel,u_email,u_birthday,u_money from zzl_user ";

pstmt = conn.prepareStatement(findSQL);

rs=pstmt.executeQuery();
         
       %>
       <br>
       <br>
       <table align="center">
          <tr>
             <th>
               <%
                 out.print("ID");
                %>
             </th>
             <th>
               <%
                 out.print("NAME");
                %>
             </th>
             <th>
               <%
                 out.print("PWD");
                %>
             </th>
             <th>
               <%
                 out.print("TEL");
                %>
             </th>
             <th>
               <%
                 out.print("EMAIL");
                %>
             </th>
             <th>
               <%
                 out.print("BRITH");
                %>
             </th>
             <th>
               <%
                 out.print("MENOY");
                %>
             </th>
          </tr>
          <%  
            while (rs.next()) {  
        %>  
        <tr>  
            <td>  
                <%  
                    out.print(rs.getLong(1));                  
                %>  
            </td>  
            <td>  
                <%  
                    out.print(rs.getString(2));  
                %>  
            </td>  
            <td>  
                <%  
                    out.print(rs.getString(3));  
                %>  
            </td>  
            <td>  
                <%  
                    out.print(rs.getString(4));  
                %>  
            </td>  
            <td>  
                <%  
                    out.print(rs.getString(5));  
                %>  
            </td> 
            <td>  
                <%  
                    out.print(rs.getDate(6));  
                %>  
            </td> 
            <td>  
                <%  
                    out.print(rs.getDouble(7));  
                %>  
            </td> 
        </tr>  
        <%  
            }  
        %>  
    </table>  
          
    <%
     JDBCUtil.close(conn, pstmt, stmt, rs);
     %>
      
  </body>

</html>

     截图:

IDNAMEPWDTELEMAILBRITHMENOY1000张三123456158025618441916911795@qq.com1996-05-211000.01020李四654321158025618441916911795@qq.com2001-05-201000.0

阅读全文
1 0
原创粉丝点击