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

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

 

显示结果:

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值