如题,上次发表了一篇添加操作的博客,后来我左思右想还是旧的把查找发出来
毕竟跟着王老师一开始都是先学查找再学添加的嘛
废话就不多说了;客官,上菜喽
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>标签:搞定,name,getString,rs,查询,查找,jsp,println,out From: https://www.cnblogs.com/yansans/p/16824603.html
<%@ 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>课程查询</title>
</head>
<body>
<center>
<form action="" method="post">
<p style="height: 20px; border: 1px solid red;text-align: center;">课程查询</p>
<p>请输入查询的课程名称:<input type="text" name="name"><p/>
<p>请输入查询的任课老师:<input type="text" name="wheres"><p/>
<p>请输入查询的上课地点:<input type="text" name="whens"><p/>
<input type="submit" name="submit" value="查询">
</form>
</center>
<%
request.setCharacterEncoding("UTF-8");
String name = request.getParameter("name");
if(name!=null){
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC","root","mysql26331");
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("select * from kebiao where clas='" + name + "'");
out.print("<center>");
while (rs.next()) {
out.println("<td>" + "课程名称:" + rs.getString("clas") + "<p/>");
out.println("<td>" + "任课老师:" + rs.getString("teacher") + "<p/>");
out.println("<td>" + "上课地点:" + rs.getString("wheres") + "<p/>");
out.println("<td>" + "上课时间:" + rs.getString("whens") + "<p/>");
}
out.print("</center>");
rs.close();
st.close();
conn.close();
}
%>
</body>
</html>