<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
    <%  
        try {  
            Class.forName("com.mysql.jdbc.Driver");  ////驱动程序名
            String url = "jdbc:mysql://localhost:3306/poitable"; //数据库名
            String username = "root";  //数据库用户名
            String password = "root";  //数据库用户密码
            Connection conn = DriverManager.getConnection(url, username, password);  //连接状态

            if(conn != null){  
                out.print("数据库连接成功!");  
                out.print("<br />"); 
%>
<table border="2">
<tr align="center">
<td width="100" number="title">ID</td>
<td width="100" name="title">Name</td>
<td width="100" age="title">Age</td>
<td width="150" age="title">Job</td>
<td width="100" age="title">Chinese</td>
<td width="100" age="title">English</td>
<td width="100" age="title">Math</td>
<td width="100" age="title">Physics</td>
<td width="100" age="title">Chemistry</td>
<td width="100" age="title">Biology</td>
</tr>
               <%
                Statement stmt = null;  
                ResultSet rs = null;  
                String sql = "SELECT * FROM classmate;";  //查询语句
                stmt = conn.createStatement();  
                rs = stmt.executeQuery(sql);  
                out.print("查询结果:");  
                out.print("<br/>");
                while (rs.next()) {
                %>
  <tr align="center">  
    <td width="100" ><%=rs.getString("id") %></td>  
    <td width="100" ><%=rs.getString("name") %></td>  
    <td width="100"><%=rs.getString("age") %></td>  
    <td width="100"><%=rs.getString("job") %></td>  
    <td width="100"><%=rs.getString("chinese") %></td>  
    <td width="100"><%=rs.getString("english") %></td>  
    <td width="100"><%=rs.getString("math") %></td>  
    <td width="100"><%=rs.getString("physics") %></td>  
    <td width="100"><%=rs.getString("chemistry") %></td>  
    <td width="100"><%=rs.getString("biology") %></td>  
  </tr>
  <%
            }  
            }else{  
                out.print("连接失败!");  
            }  
        }catch (Exception e) {        
            //e.printStackTrace();  
            out.print("数据库连接异常!");  
        }  
%> 
</table>
</body>
</html>

 

显示结果:

Mysql数据导出简单显示在页面

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-03-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-30
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-30
  • 2021-04-24
  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
相关资源
相似解决方案