一、前言二、工具三、操作过程
一、前言
本文省略部分细节,有问题详见我的另一篇文章:点击这里跳转
二、工具
MySQL数据库Navicat PremiumJava Platform (JDK) 10Tomcat 9.0.10Notepad ++mysql-connector-java-5.1.7-bin.jar (java连接MySQL工具包)三、操作过程
打开 Navicat Premium 建立单词查询数据表或者导入已有数据库:
写代码,我的代码如下
<%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> <%@page import="java.sql.*" %><html><head><title>查单词</title></head><body><% try { Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/learning","root", "root"); if(con != null){ Statement stmt = null; ResultSet rs = null; String sql = "SELECT *FROM words where Word like 'a%';"; stmt = con.createStatement(); rs = stmt.executeQuery(sql); %><table border="1" cellspacing="0" cellpadding="0" align="center" width="80%"><tr><th>序号</th><th>英文单词</th><th>过去式</th><th>过去分词</th><th>现在分词</th><th>复数形式</th> <th>中文意思</th><th>例句</th> </tr><% int xuhao=0;while (rs.next()) {xuhao++;%><tr align="center"><td><%=xuhao%></td><td><%out.print(rs.getString("Word"));%></td><td><%out.print(rs.getString("GQS"));%></td><td><%out.print(rs.getString("GQFC"));%></td><td><%out.print(rs.getString("XZFC"));%></td><td><%out.print(rs.getString("FS"));%></td><td><%out.print(rs.getString("meaning"));%></td><td><%out.print(rs.getString("lx"));%></td></tr><%}%></table><%}else{ out.print("Connection fail!"); } }catch (Exception e) { //e.printStackTrace(); out.print("Connection Exception!"); } %></body></html>
3.启动数据库
4.启动Tomcat服务器
5.打开浏览器输入http://http://192.168.43.63:8080/query.jsp