2024/4/30

所学时间:2小时

代码行数:500

博客园数:1篇

所学知识:

<%@ page import="java.util.Map" %>
<%@ page import="util.DbUtil" %>
<%@ page import="java.util.List" %>
<%@ page import="java.sql.*" %>
<%@ page import="com.example.demo1.shuju" %>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<meta name="renderer" content="webkit"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>河北省科技政策查询系统</title>
<link rel="stylesheet" href="style.css">
<style>
body {
font-family: Arial, sans-serif;
}

#header {
background-color: white;
color: #fff;
text-align: center;
padding: 10px;
display: flex;
align-items: center;
justify-content: center;
}

#header img {
height: 50px;
margin-right: 10px;
}

#search-area {
margin: 20px;
text-align: center;
align-items: center;
justify-content: center;
}

#policy-tree {
text-align: center;
}

table {
margin: 20px auto;
border-collapse: collapse;
width: 80%;
}

th, td {
padding: 10px;
}

th {
background-color: #f2f2f2;
}

td {
border-bottom: 1px solid #f2f2f2;
}

button {
background-color: #007bff;
color: white;
padding: 8px 12px;
border: none;
border-radius: 4px;
cursor: pointer;
}

button:hover {
background-color: #45a049;
}

.pagination {
margin-top: 20px;
text-align: center;
}

input[type="text"] {
width: 10%;
padding: 10px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}
select{
width: 5%;
padding: 10px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}

input[type="submit"] {
width: 5%;
padding: 10px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}

input[type="submit"] {
background-color: #007bff;
cursor: pointer;
}

</style>
</head>
<body>

<div style="width: 100%;">
<h1 style="text-align: center;color: #030098"><img src="img/LOGO.png" style="width: 30px;height: 30px">河北省科技政策查询系统
</h1>
</div>
<div style="text-align: center">
<form method="post" action="search">

政策名称&nbsp;&nbsp;<input type="text" value="${c2}" placeholder=" " name="c2">
<select name="dropdown1" value="${dropdown1}">
<option value="option1">精确</option>
<option value="option2">模糊</option>
</select>

&nbsp;&nbsp;
发文字号&nbsp;&nbsp;<input type="text" value="${c6}" placeholder="请输入发文字号" name="c6">
<select name="dropdown2" value="${dropdown2}">
<option value="option1">精确</option>
<option value="option2">模糊</option>
</select>

&nbsp;&nbsp;
发文机构&nbsp;&nbsp;<input type="text" value="${c8}" name="c8">
<select name="dropdown3" value="${dropdown3}">
<option value="option1">精确</option>
<option value="option2">模糊</option>
</select>
&nbsp;&nbsp;
全文检索&nbsp;&nbsp;<input type="text" value="${c19}" name="c19">
<select name="dropdown4" value="${dropdown4}">
<option value="option1">精确</option>
<option value="option2">模糊</option>
</select>
<input type="submit" style="color: white" value="查询">
</form>
</div>
<table border="1" style="text-align:center;">
<tr>
<td align="center" width=400px>政策名称</td>
<td align="center" width=300px>发文机构</td>
<td align="center" width=200px>颁布日期</td>
<td align="center" width=300px>政策分类</td>
</tr>
<%
List<shuju> l = (List<shuju>) request.getAttribute("l2");
if (l != null) {

int pages = 0; //待显示页面
int count = 0; //总条数
int totalpages = 0; //总页数
int limit = 10; //每页显示记录条数
count = l.size();
//由记录总数除以每页记录数得出总页数
totalpages = (int) Math.ceil(count / (limit * 1.0));
//获取跳页时传进来的当前页面参数
String strPage = request.getParameter("pages");
//判断当前页面参数的合法性并处理非法页号(为空则显示第一页,小于0则显示第一页,大于总页数则显示最后一页)
if (strPage == null) {
pages = 1;
} else {
try {
pages = java.lang.Integer.parseInt(strPage);
} catch (Exception e) {
pages = 1;
}

if (pages < 1) {
pages = 1;
}

if (pages > totalpages) {
pages = totalpages;
}
}
for (int i = 0; i < l.size(); i += limit) {
for (int j = i * limit; j<l.size()&&j < i * limit + limit; j++) {
System.out.println(l.get(j).c8);

%>
<tr>
<td align="center" title="<%=l.get(j).c2 %>"><a style="color:blue" href='show.jsp?q=<%=l.get(j).c1 %>'
onclick="javascript:return del()"><%=l.get(j).c2 %>
</a>
</td>
<td align="center"><%=l.get(j).c8 %>
</td>
<td align="center"><%=l.get(j).c9 %>
</td>
<td align="center"><%=l.get(j).c3 %>
</td>
</tr>

<%
}
}
%>
<form name="f1" method="POST" action="index.jsp" onSubmit="return checknum()">
<table border="0">
<tr>
<td>第<%=pages%>页 共<%=totalpages%>页 <a href="index.jsp?pages=1">首页</a></td>
<td><a href="index.jsp?pages=<%=(pages<1)?pages:(pages-1) %>"> 上一页</a></td>
<td><a href="index.jsp?pages=<%=(pages>=totalpages)?totalpages:(pages+1)%>"> 下一页</a></td>
<td><a href="index.jsp?pages=<%=totalpages%>">最后一页</a></td>
<td>共 <%=count%>条数据</a></td>
<td>转到第:<input type="text" name="page" size="8">页<input type="submit" value="前往" name="cndok">
</td>
</tr>
</table>

</form>
<%
} else {
%>

<%

Class.forName("com.mysql.jdbc.Driver");
// 2.使用我自己的数据库 test 获取链接
String url = "jdbc:mysql://localhost:3306/db01";
String username = "root";
String password = "123456";
Connection connection = DriverManager.getConnection(url, username, password);
//获取执行sql的对象statement
Statement statement = connection.createStatement();

int pages = 0; //待显示页面
int count = 0; //总条数
int totalpages = 0; //总页数
int limit = 10; //每页显示记录条数
//计算记录总数的第二种办法:使用mysql的聚集函数count(*)

String sql2 = "select count(*) from policy ";
ResultSet res = statement.executeQuery(sql2);
if (res.next()) {
count = res.getInt(1);//结果为count(*)表,只有一列。这里通过列的下标索引(1)来获取值
}
//由记录总数除以每页记录数得出总页数
totalpages = (int) Math.ceil(count / (limit * 1.0));
//获取跳页时传进来的当前页面参数
String strPage = request.getParameter("pages");
//判断当前页面参数的合法性并处理非法页号(为空则显示第一页,小于0则显示第一页,大于总页数则显示最后一页)
if (strPage == null) {
pages = 1;
} else {
try {
pages = java.lang.Integer.parseInt(strPage);
} catch (Exception e) {
pages = 1;
}

if (pages < 1) {
pages = 1;
}

if (pages > totalpages) {
pages = totalpages;
}
}
//由(pages-1)*limit算出当前页面第一条记录,由limit查询limit条记录。则得出当前页面的记录
res = statement.executeQuery("select * from policy order by id limit " + (pages - 1) * limit + "," + limit);
while (res.next()) {

%>
<tr>

<td id="a" align="center" title="<%=res.getObject(2)%>"><a style="color:blue"
href='show.jsp?q=<%=res.getObject(1) %>'
onclick="javascript:return del()"><%=res.getObject(2) %>
</a>
</td>
<td align="center"><%=res.getObject(8) %>
</td>
<td align="center"><%=res.getObject(9) %>
</td>
<td align="center"><%=res.getObject(3) %>
</td>
</tr>
<%
}
%>

<form name="f1" method="POST" action="index.jsp" onSubmit="return checknum()">
<table border="0">
<tr>
<td>第<%=pages%>页 共<%=totalpages%>页 <a href="index.jsp?pages=1">首页</a></td>
<td><a href="index.jsp?pages=<%=(pages<1)?pages:(pages-1) %>"> 上一页</a></td>
<td><a href="index.jsp?pages=<%=(pages>=totalpages)?totalpages:(pages+1)%>"> 下一页</a></td>
<td><a href="index.jsp?pages=<%=totalpages%>">最后一页</a></td>
<td>共 <%=count%>条数据</a></td>
<td>转到第:<input type="text" name="page" size="8">页<input type="submit" value="前往" name="cndok">
</td>
</tr>
</table>

</form>
<%
}
%>
</table>


<%--<script>--%>
<%-- function changePage(pagename){--%>
<%-- var i,page;--%>
<%-- page=document.getElementsByClassName("page");--%>
<%-- for(i=0;i<page.length;i++){--%>
<%-- page[i].style.display="none";--%>
<%-- }--%>
<%-- document.getElementById(pagename).style.display="block";--%>
<%-- }--%>
<%--</script>--%>


</body>
</html>
<%@ page import="java.sql.*" %><%--
Created by IntelliJ IDEA.
User: JC
Date: 2023/4/10
Time: 15:38
To change this template use File | Settings | File Templates.
--%>
<%--
Created by IntelliJ IDEA.
User: JC
Date: 2023/4/2
Time: 0:10
To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>查询</title>

<style>

#a {
max-width: 16ch;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
</style>
</head>
<body>
<form action="search.jsp" method="get">
<p color: black; font-family: 宋体; font-size: 10px ></p>
政策名称 <input type="text" placeholder="请输入政策名称"name="c2" > 发文字号 <input type="text" placeholder="请输入发文字号" name="c6" > 发文机构<input type="text" name="c8" /> <input type="submit" value="查询" />
</p>
</form>

<jsp:useBean id="util" class="bean.policy" scope="page" />

<table border="1" style="text-align:center;">
<tr>
<td align="center" width=400px>政策名称</td>
<td align="center" width=300px>发文机构</td>
<td align="center" width=200px>颁布日期</td>
<td align="center" width=300px>政策分类</td>
</tr>

<%
Class.forName("com.mysql.jdbc.Driver");
// 2.使用我自己的数据库 test 获取链接
String url = "jdbc:mysql://localhost:3306/db01";
String username = "root";
String password = "123456";
Connection connection = DriverManager.getConnection(url, username, password);
//获取执行sql的对象statement
Statement statement = connection.createStatement();

int pages=0; //待显示页面
int count=0; //总条数
int totalpages=0; //总页数
int limit=10; //每页显示记录条数
//计算记录总数的第二种办法:使用mysql的聚集函数count(*)
String sql2 = "select count(*) from policy ";
ResultSet rs = statement.executeQuery(sql2);
if(rs.next()){
count = rs.getInt(1);//结果为count(*)表,只有一列。这里通过列的下标索引(1)来获取值
}
//由记录总数除以每页记录数得出总页数
totalpages = (int)Math.ceil(count/(limit*1.0));
//获取跳页时传进来的当前页面参数
String strPage = request.getParameter("pages");
//判断当前页面参数的合法性并处理非法页号(为空则显示第一页,小于0则显示第一页,大于总页数则显示最后一页)
if (strPage == null) {
pages = 1;
} else {
try{
pages = java.lang.Integer.parseInt(strPage);
}catch(Exception e){
pages = 1;
}

if (pages < 1){
pages = 1;
}

if (pages > totalpages){
pages = totalpages;
}
}
//由(pages-1)*limit算出当前页面第一条记录,由limit查询limit条记录。则得出当前页面的记录
rs = statement.executeQuery("select * from policy order by viadata Desc , id limit " + (pages - 1) * limit + "," + limit ) ;
while (rs.next()){

%>
<tr>

<td id= "a" align="center" title="<%=rs.getObject(2)%>"> <a style="color:blue" href='show.jsp?q=<%=rs.getObject(1) %>' onclick="javascript:return del()"> <%=rs.getObject(2) %></a>
</td>
<td align="center"><%=rs.getObject(8) %>
</td>
<td align="center"><%=rs.getObject(9) %>
</td>
<td align="center"><%=rs.getObject(3) %>
</td>
</tr>
<%
}
%>

<form name="f1" method="POST" action="index_v148b2.jsp" onSubmit="return checknum()">
<table border="0" >
<tr>
<td>第<%=pages%>页 共<%=totalpages%>页 <a href="index_v148b2.jsp?pages=1">首页</a></td>
<td><a href="index_v148b2.jsp?pages=<%=(pages<1)?pages:(pages-1) %>"> 上一页</a></td>
<td><a href="index_v148b2.jsp?pages=<%=(pages>=totalpages)?totalpages:(pages+1)%>"> 下一页</a></td>
<td><a href="index_v148b2.jsp?pages=<%=totalpages%>">最后一页</a></td>
<td>共 <%=count%>条数据</a></td>
<td>转到第:<input type="text" name="page" size="8">页<input type="submit" value="前往" name="cndok"></td>
</tr>
</table>

</form>
</table>
<%--
Created by IntelliJ IDEA.
User: adnim
Date: 2022/10/21
Time: 0:27
To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>查询</title>
<style>

#a {
max-width: 16ch;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
</style>
</head>
<body style="text-align:center">

<%
String c2=(String)request.getParameter("c2");
String c6 =(String)request.getParameter("c6");
String c8 =(String)request.getParameter("c8");
String c19 =(String)request.getParameter("c19");
System.out.println(c2+c6+c8);
%>
<table border="1"style="text-align:center;">
<tr>
<td align="center" width=400px>政策名称</td>
<td align="center" width=300px>发文机构</td>
<td align="center" width=200px>颁布日期</td>
<td align="center" width=300px>政策分类</td>
</tr>
<%

Class.forName("com.mysql.jdbc.Driver");
// 2.使用我自己的数据库 test 获取链接
String url = "jdbc:mysql://localhost:3306/db01";
String username = "root";
String password = "123456";
Connection connection = DriverManager.getConnection(url, username, password);
//获取执行sql的对象statement
Statement statement = connection.createStatement();
ResultSet rs = null;
int pages=0; //待显示页面
int count=0; //总条数
int totalpages=0; //总页数
int limit=10; //每页显示记录条数
//计算记录总数的第二种办法:使用mysql的聚集函数count(*)
String sql= " select count(*) from policy where name = '"+c2+"' or document = '"+c6+"' or organ = '"+c8+"' or text = '"+c19+"'";
rs=statement.executeQuery(sql);
if(rs.next()){
count = rs.getInt(1);//结果为count(*)表,只有一列。这里通过列的下标索引(1)来获取值
}
//由记录总数除以每页记录数得出总页数
totalpages = (int)Math.ceil(count/(limit*1.0));
//获取跳页时传进来的当前页面参数
String strPage = request.getParameter("pages");
//判断当前页面参数的合法性并处理非法页号(为空则显示第一页,小于0则显示第一页,大于总页数则显示最后一页)
if (strPage == null) {
pages = 1;
} else {
try{
pages = java.lang.Integer.parseInt(strPage);
}catch(Exception e){
pages = 1;
}

if (pages < 1){
pages = 1;
}

if (pages > totalpages){
pages = totalpages;
}
}

String a="";
String t="select * from policy where";
int flag=0;
if(!c2.equals(a)){
t+=(" name like '%"+c2+"%' ");
flag=1;
}
if(!c6.equals(a)){
if(flag==1)
t+=(" and");
t+=(" organ like '%"+c6+"%' ");
flag=1;
}
if(!c8.equals(a)){
if(flag==1)
t+=(" and");
t+=(" document like '%"+c8+"%'");
flag=1;
}
if(!c19.equals(a)){
if(flag==1)
t+=(" and");
t+=(" text like '%"+c19+"%'");
flag=1;
}
System.out.println(t);

//String tsql= " select * from policy where name like '"+c2+"'or document like '"+c6+"' or organ like '"+c8+"' or text like '"+c19+"'";
//由(pages-1)*limit算出当前页面第一条记录,由limit查询limit条记录。则得出当前页面的记录
rs = statement.executeQuery(t);
while (rs.next()){

%>
<tr>
<td id= "a" align="center" title="<%=rs.getObject(2)%>"> <a style="color:blue" href='show.jsp?q=<%=rs.getObject(1) %>' onclick="javascript:return del()"> <%=rs.getObject(2) %></a>
</td>
<td align="center"><%=rs.getObject(8) %>
</td>
<td align="center"><%=rs.getObject(9) %>
</td>
<td align="center"><%=rs.getObject(3) %>
</td>
</tr>
<%
}
%>

<form name="f1" method="POST" action="search.jsp" onSubmit="return checknum()">
<table border="0" >
<tr>
<td>第<%=pages%>页 共<%=totalpages%>页 <a href="search.jsp?pages=1">首页</a></td>
<td><a href="search.jsp?pages=<%=(pages<1)?pages:(pages-1) %>"> 上一页</a></td>
<td><a href="search.jsp?pages=<%=(pages>=totalpages)?totalpages:(pages+1)%>"> 下一页</a></td>
<td><a href="search.jsp?pages=<%=totalpages%>">最后一页</a></td>
<td>共 <%=count%>条数据</a></td>
<td>转到第:<input type="text" name="page" size="8">页<input type="submit" value="前往" name="cndok"></td>
</tr>
</table>
</form>
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<jsp:useBean id="util" class="bean.policy" scope="page" />
<%
String q=(String)request.getParameter("q");
session.setAttribute("q",q);
%>
<table border="1"style="text-align:center;"style="width:100%;table-layout:fixed;">
<tr>
<td align="center" width="8%"></td>
</tr>
<%
Class.forName("com.mysql.jdbc.Driver");
// 2.使用我自己的数据库 test 获取链接
String url = "jdbc:mysql://localhost:3306/db01";
String username = "root";
String password = "123456";
Connection connection = DriverManager.getConnection(url, username, password);
//获取执行sql的对象statement
Statement statement = connection.createStatement();
ResultSet rs=null;
try {
String sql = "select * from policy where id = '"+q+"'";
rs=statement.executeQuery(sql);
while(rs.next()){
%>
<tr>
<td align="center"><%=rs.getObject(19)%></td>
</tr>
<%

}
} catch (SQLException e) {
e.printStackTrace();
}finally{
util.close(rs);
util.close(connection);
}
%>
</table>
</form>
</body>
</html>
.navbar{
background-color: #000dff;
overflow: hidden;
}

.navbar a{
float: left;
display: block;
color: #fff200;
text-align: center;
padding: 30px 50px;
text-display: none;
text-decoration: none;
}

.navbar a:hover{
background-color: aliceblue;
color: black;
}

.page{
text-align: center;
display: none;
width: 100%;
height: 710px;
background-image: linear-gradient(to bottom right, rgb(250, 243, 108), rgb(10, 122, 250));

}

.page.active{
display:block;
}

.page input{
border-radius: 4px; /* 添加圆角边框 */
background-color: #f6e3e3; /* 自定义背景色 */
color: #000000; /* 自定义文字颜色 */
box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.15); /* 添加阴影效果 */
width: 190px;
padding: 7px;
}

.page button {
text-align: center;
padding: 10px;
margin: 0 auto;
width: 200px;
margin-top: 40px;
background-image: linear-gradient(to right, rgba(238, 10, 10, 0.61), #fab400);
color: #fff;
}




</table>
package com.example.demo1;

import java.math.BigInteger;
import java.util.Date;

public class shuju {
public String c2=null,c3=null,c6=null,c8=null,c19=null;
public Date c9;
public BigInteger c1;

public shuju(BigInteger c1,String c2,String c3,String c6,String c8,Date c9,String c19) {
this.c1=c1;
this.c2 = c2;
this.c3=c3;
this.c6 = c6;
this.c8 = c8;
this.c9=c9;
this.c19 = c19;
}

public String getC2() {
return c2;
}


public String getC6() {
return c6;
}

public String getC8() {
return c8;
}

public String getC19() {
return c19;
}

public void setC8(String c8) {
this.c8 = c8;
}

public void setC6(String c6) {
this.c6 = c6;
}

public void setC19(String c19) {
this.c19 = c19;
}

public void setC2(String c2) {
this.c2 = c2;
}
package com.example.demo1;

import java.io.*;
import java.math.BigInteger;
import java.sql.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

@WebServlet(name = "search", value = "/search")
public class search extends HttpServlet {
private String message;

public void init() {
message = "Hello World!";
}
public List<shuju> l=new ArrayList<>();

public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
String c2=request.getParameter("c2");
String c6=request.getParameter("c6");
String c8=request.getParameter("c8");
String c19=request.getParameter("c19");
String dropdown1=request.getParameter("dropdown1");
String dropdown2=request.getParameter("dropdown2");
String dropdown3=request.getParameter("dropdown3");
String dropdown4=request.getParameter("dropdown4");

try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
// 2.使用我自己的数据库 test 获取链接
String url = "jdbc:mysql://localhost:3306/db01";
String username = "root";
String password = "123456";
Connection connection = null;
Statement statement = null;
try {
connection = DriverManager.getConnection(url, username, password);
statement = connection.createStatement();
System.out.println("1");
} catch (SQLException e) {
throw new RuntimeException(e);
}
ResultSet rs = null;
int pages=0; //待显示页面
int count=0; //总条数
int totalpages=0; //总页数
int limit=10; //每页显示记录条数
//计算记录总数的第二种办法:使用mysql的聚集函数count(*)

String a="";
String t="select count(*) from policy where";
int flag=0;
if(!c2.equals(a)){
t+=(" name like '%"+c2+"%' ");
flag=1;
}
if(!c6.equals(a)){
if(flag==1)
t+=(" and");
t+=(" organ like '%"+c6+"%' ");
flag=1;
}
if(!c8.equals(a)){
if(flag==1)
t+=(" and");
t+=(" document like '%"+c8+"%'");
flag=1;
}
if(!c19.equals(a)){
if(flag==1)
t+=(" and");
t+=(" text like '%"+c19+"%'");
flag=1;
}
System.out.println(t);
String sql= "select * from policy where organ like '%国务院%' ";
try {
rs=statement.executeQuery(sql);
while(rs.next()){
System.out.println("fsfsfsfesf");
count = rs.getInt(1);//结果为count(*)表,只有一列。这里通过列的下标索引(1)来获取值
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
try {
if(rs.next()){
count = rs.getInt(1);//结果为count(*)表,只有一列。这里通过列的下标索引(1)来获取值
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
System.out.println(count);
//由记录总数除以每页记录数得出总页数
totalpages = (int)Math.ceil(count/(limit*1.0));
//获取跳页时传进来的当前页面参数
String strPage = request.getParameter("pages");
//判断当前页面参数的合法性并处理非法页号(为空则显示第一页,小于0则显示第一页,大于总页数则显示最后一页)
if (strPage == null) {
pages = 1;
} else {
try{
pages = java.lang.Integer.parseInt(strPage);
}catch(Exception e){
pages = 1;
}

if (pages < 1){
pages = 1;
}

if (pages > totalpages){
pages = totalpages;
}
}

a="";
t="select * from policy where";
flag=0;
if(!c2.equals(a)){
t+=(" name like '%"+c2+"%' ");
flag=1;
}
if(!c6.equals(a)){
if(flag==1)
t+=(" and");
t+=(" organ like '%"+c6+"%' ");
flag=1;
}
if(!c8.equals(a)){
if(flag==1)
t+=(" and");
t+=(" document like '%"+c8+"%'");
flag=1;
}
if(!c19.equals(a)){
if(flag==1)
t+=(" and");
t+=(" text like '%"+c19+"%'");
flag=1;
}
System.out.println(t);
ResultSet res = null;

//String tsql= " select * from policy where name like '"+c2+"'or document like '"+c6+"' or organ like '"+c8+"' or text like '"+c19+"'";
//由(pages-1)*limit算出当前页面第一条记录,由limit查询limit条记录。则得出当前页面的记录
try {
res = statement.executeQuery(t);
} catch (SQLException e) {
throw new RuntimeException(e);
}

while(true){
try {
System.out.println("adfvcasdfvs");
if (!res.next()) break;System.out.println("adfvcasdfvs");
} catch (SQLException e) {
throw new RuntimeException(e);
}
shuju s=null;
try {
s=new shuju((BigInteger) res.getObject(1),(String) res.getObject(2),(String) res.getObject(3), (String) res.getObject(6), (String) res.getObject(8),(Date) res.getObject(9), (String) res.getObject(19));
} catch (SQLException e) {
throw new RuntimeException(e);
}
l.add(s);
}

request.setAttribute("c2",c2);
request.setAttribute("c6",c6);
request.setAttribute("c8",c8);
request.setAttribute("c19",c19);
request.setAttribute("l2",l);
System.out.println(l.size());
try {
request.getRequestDispatcher("index.jsp").forward(request,response);
} catch (ServletException e) {
throw new RuntimeException(e);
}
}

public void destroy() {
}
}
package bean;

import java.sql.*;

public class policy {
private String c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16,c17,c18,c19;

public String getC1() {
return c1;
}

public void setC1(String c1) {
this.c1 = c1;
}

public String getC2() {
return c2;
}

public void setC2(String c2) {
this.c2 = c2;
}

public String getC3() {
return c3;
}

public void setC3(String c3) {
this.c3 = c3;
}

public String getC4() {
return c4;
}

public void setC4(String c4) {
this.c4 = c4;
}

public String getC5() {
return c5;
}

public void setC5(String c5) {
this.c5 = c5;
}

public String getC6() {
return c6;
}

public void setC6(String c6) {
this.c6 = c6;
}

public String getC7() {
return c7;
}

public void setC7(String c7) {
this.c7 = c7;
}

public String getC8() {
return c8;
}

public void setC8(String c8) {
this.c8 = c8;
}

public String getC9() {
return c9;
}

public void setC9(String c9) {
this.c9 = c9;
}

public String getC10() {
return c10;
}

public void setC10(String c10) {
this.c10 = c10;
}

public String getC11() {
return c11;
}

public void setC11(String c11) {
this.c11 = c11;
}

public String getC12() {
return c12;
}

public void setC12(String c12) {
this.c12 = c12;
}

public String getC13() {
return c13;
}

public void setC13(String c13) {
this.c13 = c13;
}

public String getC14() {
return c14;
}

public void setC14(String c14) {
this.c14 = c14;
}

public String getC15() {
return c15;
}

public void setC15(String c15) {
this.c15 = c15;
}

public String getC16() {
return c16;
}

public void setC16(String c16) {
this.c16 = c16;
}

public String getC17() {
return c17;
}

public void setC17(String c17) {
this.c17 = c17;
}

public String getC18() {
return c18;
}

public void setC18(String c18) {
this.c18 = c18;
}

public String getC19() {
return c19;
}

public void setC19(String c19) {
this.c19 = c19;
}
public Connection getConnection()//连接数据库
{
try{
Class.forName("com.mysql.cj.jdbc.Driver");
System.out.println("加载驱动成功");
}catch(ClassNotFoundException e)
{
e.printStackTrace();
}
String user="root";
String password="123456";
String url ="jdbc:mysql://localhost:3306/user?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true";
Connection con=null;
try{
con= DriverManager.getConnection(url,user,password);
System.out.println("数据库连接成功");
}catch(SQLException e)
{
e.printStackTrace();
}
return con;
}
//**********************************************************************
//关闭方法
public void close (Connection con)
{
try{
if(con!=null)
{
con.close();
}
}catch(SQLException e)
{
e.printStackTrace();
}
}
public void close (PreparedStatement preparedStatement)
{
try{
if(preparedStatement!=null)
{
preparedStatement.close();
}
}catch(SQLException e)
{
e.printStackTrace();
}
}
public void close(ResultSet resultSet)
{
try{
if(resultSet!=null)
{
resultSet.close();
}
}catch(SQLException e)
{
e.printStackTrace();
}
}

public static void main(String[] args)
{
//Data a=new Data();
}
}

}
posted @ 2024-05-06 23:01  为20岁努力  阅读(6)  评论(0编辑  收藏  举报