2024.9.20(周五)
完善昨天的查的部分
<%@ page import="java.sql.*" %> <%@ page import="util.DBConnection" %> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>统计结果</title> </head> <body> <h2>统计结果</h2> <% String criteria = request.getParameter("criteria"); String sql = ""; if ("tech_activity_type".equals(criteria)) { sql = "SELECT tech_activity_type, COUNT(*) as count FROM tech_requirements GROUP BY tech_activity_type"; } else if ("institution_type".equals(criteria)) { sql = "SELECT institution_type, COUNT(*) as count FROM tech_requirements GROUP BY institution_type"; } Connection con = null; Statement stmt = null; ResultSet res = null; try { con = DBConnection.getConnection(); stmt = con.createStatement(); res = stmt.executeQuery(sql); if (res.isBeforeFirst()) { %> <table border="1"> <tr> <th>类型</th> <th>数量</th> </tr> <% while (res.next()) { if ("tech_activity_type".equals(criteria)) { out.println("<tr><td>" + res.getString("tech_activity_type") + "</td><td>" + res.getInt("count") + "</td></tr>"); } else if ("institution_type".equals(criteria)) { out.println("<tr><td>" + res.getString("institution_type") + "</td><td>" + res.getInt("count") + "</td></tr>"); } } %> </table> <% } else { out.println("<p>没有找到符合条件的记录。</p>"); } } catch (Exception e) { e.printStackTrace(); out.println("<p>错误信息:" + e.getMessage() + "</p>"); } finally { if (res != null) { try { res.close(); } catch (SQLException e) { e.printStackTrace(); } } if (stmt != null) { try { stmt.close(); } catch (SQLException e) { e.printStackTrace(); } } if (con != null) { try { con.close(); } catch (SQLException e) { e.printStackTrace(); } } } %> </body> </html>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步