如何在JSP頁面顯示Oracle數據庫內容

<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>

     截圖:

ID NAME PWD TEL EMAIL BRITH MENOY
1000 張三 123456 15802561844 [email protected] 1996-05-21 1000.0
1020 李四 654321 15802561844 [email protected] 2001-05-20 1000.0

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章