⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 query.jsp

📁 完成论文的在线查询提交和下载,不用登录密码即可上传下载
💻 JSP
字号:
<%@ page contentType="text/html;charset=gb2312" %>
<html>
<title>查询数据库</title>
</head>
<body  background="20060223155018665675.jpg"  >
<!-- 设置脚本语言为java,引用java.sql包 -->
<%@ page language="java" import="java.sql.*" %>
<%
String title=request.getParameter("title");
String authorname=request.getParameter("authorname");
String teachername=request.getParameter("teachername");
String major=request.getParameter("major");
String keyword=request.getParameter("keyword");
String mysql;
%>
<%
    Connection con = null;

    try {
      // 登记JDBC驱动程序
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      //连接数据库
      con = DriverManager.getConnection("jdbc:odbc:cjx","", "");
      //创建语句对象
      Statement statement = con.createStatement();
      //执行SQL语句

String sql="";
String sqlWhere="";	 

sql="select * from bookitem ";
  if(title.length()>0)
    sqlWhere+="and title like '%" + title + "%'";
  if(authorname.length()>0)
    sqlWhere+="and authorname like '%" + authorname + "%'";

  if(teachername.length()>0)
    sqlWhere+="and teachername like '%" + teachername + "%'";

  if(major.length()>0)
    sqlWhere+="and major like '%" + major + "%'";

  if(keyword.length()>0)
    sqlWhere+="and keyword like '%" + keyword + "%'";  

  if(sqlWhere.length()>0)
    sql+=" where " + sqlWhere.substring(4,sqlWhere.length());
//  if(sql=="select * from bookitem")
 //  {alert("查询不能为空!");
//    return false;}
//          mysql="select * from bookitem where title like '"+title+"' and authorname like '"+authorname+"' and //teachername like '"+teachername+"' and major like '"+major+"' and keyword like '"+keyword+"' ";       
	  //将Unicode编码的String类型数据转化为“ISO-8859-1”编码
          byte[] temp=sql.getBytes("ISO-8859-1");
          String mysql_str=new String(temp);

       	  ResultSet rs = statement.executeQuery(mysql_str);
      //取得结果,输出到屏幕
      %>
      <!-- 以HTML表格形式输出结果-->
      <table border="1">
      <tr>
      <th>论文题目</th><th>作者姓名</th><th>指导教师</th><th>专业</th><th>摘要</th>
      <th>关键词</th><th>word文档</th>
      
      <%
      while ( rs.next() ) {
        out.println("<tr>\n<td>" + rs.getString("title") + "</td>");
        out.println("<td>" + rs.getString("authorname") + "</td>");
        out.println("<td>" + rs.getString("teachername") + "</td>");
        out.println("<td>" + rs.getString("major") + "</td>");
	out.println("<td>" + rs.getString("ps") + "</td>");
        out.println("<td>" + rs.getString("keyword") + "</td>");
        
	out.println("<td>" + rs.getString("wordfile") + "</td>\n</tr>");
      }
      //关闭结果集<a href="index.html">下载</a><br>
      rs.close();
    }
    catch (Exception e) {
      out.println(e.getMessage());
    }
   //关闭数据库连接
   con.close();
 %>

<a href="do_download.jsp" ><font size=5 color="blue">下载论文</font></a><br>
<a href="first.htm" ><font size=5 color="blue">返回首页</font></a><br>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -