<%@ page language="java" import="java.sql.*" pageEncoding="GB2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>mysql</title>
    
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->  </head>
  
  <body>
 <b><center>
 <font size= 4 color= red> SQL数据库的friends数据表一览</font><br>
 <hr><br>
 <%
   Class.forName("com.mysql.jdbc.Driver");
   String url ="jdbc:mysql://localhost/mysql";
  String user="root";
  String password ="yava";
  Connection con = DriverManager.getConnection(url,user,password);
  Statement stmt = con.createStatement();
  ResultSet rs   = stmt.executeQuery ("SELECT * FROM friends");
    %></b>
    <table bgcolor =black>
    <tr bgcolor= yellow >
       <td><b><div><center>ID </center></div></b></td>
       <td><b><div> <center>id </center></div></b></td>
       <td><b><div><center>name</center></div></b></td>
       </tr>
       <%
       while (rs.next())
       {
        %>
      <tr bgcolor=cyan>
      <td><b><div><center><%=rs.getRow() %></center></div></b></td>
       <td><b><div><center><%=rs.getInt("id")
        %>
       </center></div></b></td>
       <td><b><div><center><%=rs.getString("name") %>
       </center></div></b></td>
       </tr>
       <%
       }
       rs.close();
       stmt.close();
       con.close();
        %>
        </table>
        </center></b>
         <br>
  </body>
</html>

解决方案 »

  1.   

    <%@ page language="java" import="java.sql.*" pageEncoding="GB2312"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>mysql</title>
        
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->  </head>
      
      <body>
     <b><center>
     <font size= 4 color= red> SQL数据库的friends数据表一览</font><br>
     <hr><br>
     <%
       Class.forName("com.mysql.jdbc.Driver");
       String url ="jdbc:mysql://localhost/mysql";//mysql为数据库名
      String user="root";
      String password ="yava";
      Connection con = DriverManager.getConnection(url,user,password);
      Statement stmt = con.createStatement();
      ResultSet rs   = stmt.executeQuery ("SELECT * FROM friends");//friends为数据表名
        %></b>
        <table bgcolor =black>
        <tr bgcolor= yellow >
           <td><b><div><center>ID </center></div></b></td>
           <td><b><div> <center>id </center></div></b></td>
           <td><b><div><center>name</center></div></b></td>
           </tr>
           <%
           while (rs.next())
           {
            %>
          <tr bgcolor=cyan>
          <td><b><div><center><%=rs.getRow() %></center></div></b></td>
           <td><b><div><center><%=rs.getInt("id")
            %>
           </center></div></b></td>
           <td><b><div><center><%=rs.getString("name") %>
           </center></div></b></td>
           </tr>
           <%
           }
           rs.close();
           stmt.close();
           con.close();
            %>
            </table>
            </center></b>
             <br>
      </body>
    </html>