《JSP》JSP学习(六)——统计单词个数

一、单词个数统计页面

     博主下载的单词表为CET6核心词汇表,一共601个单词,即导入数据库中的表“cet6”,统计表中以“a、b······z”开头的单词个数,并以表格的形式显示在网页上。程序主要通过SQL语句SELECT 进行查询,将符合条件的单词提取,再利用ResultSet函数中的next方法对提取出来的单词遍历,每遍历一遍,整数型变量“rscount”+1,最终的计数便是单词个数。

cet6:
《JSP》JSP学习(六)——统计单词个数_第1张图片
count.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>  
<%@ page import="com.mysql.jdbc.Driver" %>   
<%@ page import="java.sql.*" %>





count


 
 
 
 

统计结果

<% //加载驱动程序 String driverName="com.mysql.jdbc.Driver"; //数据库信息 String userName="root"; //密码 String userPasswd="yle30268"; //数据库名 String dbName="tables"; //表名 String url="jdbc:mysql://localhost:3306/"+dbName+"?user="+userName+"&password="+userPasswd; Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection conn=DriverManager.getConnection(url); Statement stmt = conn.createStatement(); String initial[] = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}; for(int i=0;i <% } %>
<%=initial[i]%>为首的单词数:<%=rscount %>
二、统计演示

     根据上图“cet6”可以看出一共有601条单词记录,所以统计出来的结果之和也应该是601个单词,其中以“z”开头的单词只有一个。

你可能感兴趣的:(JSP)