大型数据库应用技术-课堂测试2(HABSE数据库应用)
石家庄铁道大学2022年秋季
2020 级课堂测试试卷—HBASE数据库应用
一、 测试题目
1、完成《河北省重大技术需求征集》基本信息填报功能,样表如下所示:
|
*机构全称 |
|
归口管理部门 |
|
|||||||
|
*通讯地址 |
|
*所在地域 |
|
|||||||
|
网 址 |
|
*电子信箱 |
|
|||||||
|
*法人代表 |
|
邮政编码 |
|
|||||||
|
*联 系 人 |
|
*电 话 |
1.固定 2.手机 |
|||||||
|
传 真 |
|
|||||||||
|
*机构属性 |
○企业 ○高等院校 ○研究机构 ○其他 |
|||||||||
|
*机构简介(主要包括基本情况、现有研究基础等,限500字以内) |
||||||||||
|
*技术需求名称 |
|
*需求时限 |
年至 年 |
|||||||
|
*技术需求概述 1、主要问题(需要解决的重大技术问题,限500字以内) 2、技术关键(所需的关键技术、主要指标,限500字以内) 3、预期目标(技术创新性、经济社会效益,限500字以内) |
||||||||||
|
*关键字:(1-5个) 五个文本框(只能逐个顺序录入) |
||||||||||
|
拟投入资金总额 |
万元 |
|||||||||
|
*技术需求解决方式 (位置调整) |
○独立研发 ○委托研发 ○合作研发 ○其他 |
|||||||||
|
合作意向单位 (选填) |
||||||||||
|
*科技活动类型 |
○基础研究 ○应用研究 ○试验发展 ○研究与试验发展成果应用 ○技术推广与科技服务 ○生产性活动 |
|||||||||
|
学科分类(限基础研究填写) |
(参见学科分类)三级下拉文本框 |
|||||||||
|
需求技术所属领域 (非基础研究填写) |
□电子信息 □光机电一体化 □生物技术与制药 □新材料及应用 □ 现代农业 □新能源与高效节能 □资源与环境 □高技术服务业 □海洋 □社会公共事业 □医疗卫生 □其它(注明) (可多选) |
|||||||||
|
需求技术 应用行业 (非基础研究填写) |
(参见国民经济行业分类)三级下拉文本框
|
|||||||||
2、实现按照机构全称、所在地域、技术需求名称、关键词的多条件查询;
3、实现按照科技活动类型或机构属性的统计查询。
4、后台数据库要求使用HBASE数据库,并将新数据存入HBase新建表中。
5、实现从数据库中将新数据读出展示在前台页面。
二、评分等级:
A级:完成上述全部功能等功能。
B级:实现信息填报功能,未按要求实现全部功能。
C级:实现部分功能,可实现数据库连接,并在数据库中建立相应的表。
D级:安装成功Hbase,无法实现编程,可以实现手动建表。



xuqiubiao.java
package bean;
public class xuqiubiao {
String name;
String xuqiugaishu;
String yanjiufangshi;
String hezuomoshi;
String tourujin;
String zhuangtai;
String shijian;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getXuqiugaishu() {
return xuqiugaishu;
}
public void setXuqiugaishu(String xuqiugaishu) {
this.xuqiugaishu = xuqiugaishu;
}
public String getYanjiufangshi() {
return yanjiufangshi;
}
public void setYanjiufangshi(String yanjiufangshi) {
this.yanjiufangshi = yanjiufangshi;
}
public String getHezuomoshi() {
return hezuomoshi;
}
public void setHezuomoshi(String hezuomoshi) {
this.hezuomoshi = hezuomoshi;
}
public String getTourujin() {
return tourujin;
}
public void setTourujin(String tourujin) {
this.tourujin = tourujin;
}
public String getZhuangtai() {
return zhuangtai;
}
public void setZhuangtai(String zhuangtai) {
this.zhuangtai = zhuangtai;
}
public String getShijian() {
return shijian;
}
public void setShijian(String shijian) {
this.shijian = shijian;
}
public xuqiubiao(String name,String xuqiugaishu,String yanjiufangshi,String hezuomoshi,String tourujin,String zhuangtai,String shijian) {
this.name = name;
this.xuqiugaishu = xuqiugaishu;
this.yanjiufangshi = yanjiufangshi;
this.hezuomoshi = hezuomoshi;
this.tourujin = tourujin;
this.zhuangtai = zhuangtai;
this.shijian = shijian;
}
}
yonghu.java
package bean;
public class yonghu {
String name;
String number;
String password;
String danwei;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getDanwei() {
return danwei;
}
public void setDanwei(String danwei) {
this.danwei = danwei;
}
}
dao.java
package dao;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import bean.*;
import java.sql.ResultSet;
import java.sql.Statement;
import dbutil.DBUtil;
public class dao {
public int adduser(String number,String password,String name,String danwei)
{
Connection conn = DBUtil.getConn();//这里就是从DBUtil类里面得到连接
Statement state =null;
ResultSet rs = null;
int flag=0;
try
{
String sql = "insert into user(name,password,number,danwei)values('"+name+"','"+password+"','"+number+"','"+danwei+"')";
state = conn.createStatement();
int count = state.executeUpdate(sql);
if(count>0) {
System.out.println("数据插入成功");
}else {
System.out.println("数据插入失败了QAQ");
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
DBUtil.close(rs, state, conn);
}
return flag;
}
public String login(String name,String password)
{
Connection conn = DBUtil.getConn();//这里就是从DBUtil类里面得到连接
Statement state =null;
ResultSet rs = null;
try
{
String sql = "select * from user";
state = conn.createStatement();
rs=state.executeQuery(sql);
while(rs.next())
{
String number1=rs.getString("name");
String password1=rs.getString("password");
System.out.println(number1);
System.out.println(password1);
if(number1.equals(name)&&password1.equals(password))
{
//System.out.println(user1);
System.out.println("name1");
return "正确";
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
DBUtil.close(rs, state, conn);
}
System.out.println("name2");
return "错误";
}
public int addxuqiu(String name,String xuqiugaishu,String yanjiufangshi,String hezuomoshi,String tourujin,String zhuangtai)
{
Connection conn = DBUtil.getConn();//这里就是从DBUtil类里面得到连接
Statement state =null;
ResultSet rs = null;
int flag=0;
try
{
String sql = "insert into xuqiuxinxi(name,xuqiugaishu,yanjiufangshi,hezuomoshi,tourujin,zhuangtai)values('"+name+"','"+xuqiugaishu+"','"+yanjiufangshi+"','"+hezuomoshi+"','"+tourujin+"','"+zhuangtai+"')";
state = conn.createStatement();
int count = state.executeUpdate(sql);
if(count>0) {
System.out.println("数据插入成功");
}else {
System.out.println("数据插入失败了QAQ");
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
DBUtil.close(rs, state, conn);
}
return flag;
}
public int updatamima(String name,String password)
{
Connection conn = DBUtil.getConn();//这里就是从DBUtil类里面得到连接
Statement state =null;
ResultSet rs = null;
int flag=0;
try
{
String sql = "update xuqiuxinxi set name='"+name+"',password='"+password+"'";
state = conn.createStatement();
int count = state.executeUpdate(sql);
if(count>0) {
System.out.println("数据插入成功");
}else {
System.out.println("数据插入失败了QAQ");
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
DBUtil.close(rs, state, conn);
}
return flag;
}
public static List<xuqiubiao> xuqiu(String ReadyState1,String Capacity1)
{
String sql = "select * from xuqiuxinxi";
Connection conn = DBUtil.getConn();//这里就是从DBUtil类里面得到连接
Statement state =null;
List<xuqiubiao> list = new ArrayList<>();
ResultSet rs = null;
int flag=0;
try
{
state = conn.createStatement();
rs=state.executeQuery(sql);
xuqiubiao kc=null;
while(rs.next())
{
String name=rs.getString("name");
String xuqiugaishu=rs.getString("xuqiugaishu");
String yanjiufangshi=rs.getString("yanjiufangshi");
String hezuomoshi=rs.getString("hezuomoshi");
String tourujin=rs.getString("tourujin");
String zhuangtai=rs.getString("zhuangtai");
String shijian=rs.getString("shijian");
kc =new xuqiubiao(name,xuqiugaishu,yanjiufangshi,hezuomoshi,tourujin,zhuangtai,shijian);
//System.out.println(name+"=========");
list.add(kc);
}
// System.out.println("3");
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
DBUtil.close(rs, state, conn);
}
return list;
}
}
DBUtil.java
package dbutil;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBUtil {//这个类就是套模板如果需要用的时候只需要改数据库(db)的名字即可*******
//public static String db_url="jdbc:mysql://localhost:3306/database?uerUnicode=true&characterEncoding=UTF-8";
public static String db_url="jdbc:mysql://localhost:3306/database3?serverTimezone=GMT%2B8&serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8";//db是数据库的名字
//这是连接数据库,servlet是数据库的名称,uerUnicode=true&characterEncoding=UTF-8是将字符集设置为utf-8,避免乱码。
public static String db_user="root";//数据的用户名
public static String db_password="UJuqCT-az5(f";//数据库的密码
public static Connection getConn()//获取连接,返回Connection类型,必须设置为static这样才能在其他类中使用
{
Connection conn=null;
try
{
Class.forName("com.mysql.cj.jdbc.Driver");//加载驱动
conn=DriverManager.getConnection(db_url,db_user,db_password);//连接数据库
}
catch(Exception e)
{
e.printStackTrace();
}
return conn;
}
public static void close(Statement state,Connection conn)//关闭函数
{
if(state!=null)//只有状态和连接时,先关闭状态
{
try
{
state.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
if(conn!=null)
{
try
{
conn.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
public static void close(ResultSet rs,Statement state,Connection conn)
{
if(rs!=null)//有结果集,状态和连接时,先关闭结果集,在关闭状态,在关闭连接
{
try
{
rs.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
if(state!=null)
{
try
{
state.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
if(conn!=null)
{
try
{
conn.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
}
Servlet.java
package servlet;
import java.io.IOException;
import java.util.List;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import bean.*;
import dao.*;
@WebServlet("/r2")
public class Servlet extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {
return;
}
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");// 设置字符集,避免乱码
// 获取jsp界面需要进行的操作,
String method = req.getParameter("method");
//System.out.println("============");
if (method.equals("addyonghu"))// 转到login函数
{
addyonghu(req,resp);
// System.out.println("正在执行信息录入操作");
}
if (method.equals("login"))// 转到login函数
{
login(req,resp);
// System.out.println("正在执行信息录入操作");
}
if (method.equals("addxuqiu"))// 转到login函数
{
addxuqiu(req,resp);
// System.out.println("正在执行信息录入操作");
}
if (method.equals("updatamima"))// 转到login函数
{
updatamima(req,resp);
// System.out.println("正在执行信息录入操作");
}
if (method.equals("liulanxuqiu"))// 转到login函数
{
liulanxuqiu(req,resp);
// System.out.println("正在执行信息录入操作");
}
}
private void addyonghu(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");
String number=req.getParameter("number");
String password = req.getParameter("password");
String name=req.getParameter("name");
String danwei=req.getParameter("danwei");
System.out.println("name");
dao userdao = new dao();
// System.out.println("============");
userdao.adduser(number,password,name,danwei);
// System.out.println("============");
req.getRequestDispatcher("/login.jsp").forward(req,resp);
}
private void login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");
String name=req.getParameter("name");
String password = req.getParameter("password");
System.out.println(name);
System.out.println(password);
// String user=req.getParameter("user");
//System.out.println("name");
dao userdao = new dao();
String log=userdao.login(name,password);
System.out.println(log);
if(log.equals("正确"))
{
System.out.println("name");
req.getRequestDispatcher(".jsp").forward(req,resp);
//System.out.println("select============");
}
else req.getRequestDispatcher("/login.jsp").forward(req,resp);
}
private void addxuqiu(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");
String name=req.getParameter("name");
String xuqiugaishu = req.getParameter("xuqiugaishu");
String yanjiufangshi=req.getParameter("yanjiufangshi");
String hezuomoshi=req.getParameter("hezuomoshi");
String tourujin=req.getParameter("tourujin");
String zhuangtai="";
zhuangtai+="未审核";
dao userdao = new dao();
// System.out.println("============");
userdao.addxuqiu(name,xuqiugaishu,yanjiufangshi,hezuomoshi,tourujin,zhuangtai);
// System.out.println("============");
req.getRequestDispatcher("/gongnengye.jsp").forward(req,resp);
}
private void updatamima(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");
String number=req.getParameter("name");
String password = req.getParameter("password");
//System.out.println("name");
dao userdao = new dao();
// System.out.println("============");
userdao.updatamima(number,password);
// System.out.println("============");
req.getRequestDispatcher("/gongnengye.jsp").forward(req,resp);
}
private void liulanxuqiu(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
// System.out.println("12");
resp.setContentType("text/html;charset=utf-8");
String ReadyState=req.getParameter("ReadyState");
String Capacity=req.getParameter("Capacity");
List<xuqiubiao> kc=dao.xuqiu(ReadyState,Capacity);
//System.out.println("2");
req.setAttribute("kc", kc);
req.getRequestDispatcher("xuqiushenhe.jsp").forward(req, resp);
}
}
gongnengye.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
body{text-align:center}
input{
font-size: 20px;
text-align: center;
}
</style>
</head>
<body>
<p>请选择功能</p>
<a href="xuqiuzhengji.jsp">
<button>需求征集</button>
</a>
<form action="/Test5/r2?method=liulanxuqiu" method="post" onsubmit="return check();">
<p>
<input type="submit" value="浏览需求">
</p>
</form>
<a href=".jsp">
<button>需求审核</button>
</a>
<a href="yonghuzhuce.jsp">
<button>用户注册</button>
</a>
<a href="mimaxiugai.jsp">
<button>修改密码</button>
</a>
</body>
</html>
login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
body{text-align:center}
input{
font-size: 20px;
text-align: center;
}
</style>
</head>
<body>
<form action="/Test5/r2?method=login"method="post" onsubmit="return check();">
<div id="登录界面">
<h1>Login</h1>
<table align="center">
<tr>
<th>账号</th>
<td>
<input type="text" name="name">
</td>
</tr>
<tr>
<th>密码</th>
<td><input type="password" name = "password">
</td>
</tr>
<td colspan="2"><input type="submit" name="submit" value="提交"> <input type="reset" value="重置"></td>
</tr>
</table>
</form>
<div><a href="yonghuzhuce.jsp">注册</a> <a href="createyonghu.jsp"></a></div>
</div>
</body>
</html>
mimaxiugai.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
body{text-align:center}
</style>
</head>
<body>
<form action="/Test5/r2?method=updatamima"method="post" onsubmit="return check();">
<h1>请输入信息</h1>
1.用户名:<input type="text" name="name"> <br/>
2.密码:<input type="password" name="password" id="pwd"> <br/>
3.确认密码:<input type="password" name=password1 id="pwd1" onkeyup="checkpassword()"> <br>
<input type ="submit" value="提交">
<input type="reset" value="重置" >
</form>
</body>
</html>
xuqiushenhe.jsp
<%@page import="java.util.*"%>
<%@page import="bean.*"%>
<%@page import="dao.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
body{text-align:center}
</style>
</head>
<body>
<div align="center">
<h1 style="color: black;"> 清单 <a href="xuqiuzhengji.html">添加技术需求</a> </h1>
<table class="tb" border="0px">
<tr>
<tr>
<th>需求编号</th>
<th>填报时间</th>
<th>状态</th>
<th>操作</th>
</tr>
<%List<xuqiubiao> list=(List<xuqiubiao>)request.getAttribute("kc");
//String s="sd";
//request.getSession().setAttribute("ss",s);
for(xuqiubiao kc : list){
%>
<tr>
<td><%=kc.getName() %></td>
<td><%=kc.getShijian() %></td>
<td><%=kc.getZhuangtai() %></td>
<td> <a href=".jsp">
<button>查看审核</button>
</a> </td>
</tr>
<%
}
%>
</table></div>
<!--
<input type="hidden" name="ID" id="ID" value="${kc[0]}">
<td><input type="hidden" name="name" id="name" value="${kc[1]}"></td>
<tr>
<td><input type="hidden" name="renshu" id="renshu" value="${kc[2]}"></td>
</tr>
<td><input type="hidden" name="jiaoshi" id="jiaoshi" value="${kc[4]}"></td>
-->
</body>
</html>
xuqiuzhengji.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="/Test5/r2?method=addxuqiu"method="post" onsubmit="return check();">
<h2>河北省重大技术需求征集表</h2>
技术需求名称:<input type="text" name="name"><br>
重大科技需求概述(主要内容,技术指标、预期经济和社会效益等,限500字)
<input type="text" name="xuqiugaishu" maxlength="500"><br>
研究类型:<input type="checkbox" name="yanjiufangshi" value="基础研究">基础研究
<input type="checkbox" name="yanjiufangshi" value="应用研究">应用研究
<input type="checkbox" name="yanjiufangshi" value="试验开发">试验开发
<input type="checkbox" name="yanjiufangshi" value="研究发展与成果应用">研究发展与成果应用<br>
<input type="checkbox" name="yanjiufangshi" value="技术推广与科技服务">技术推广与科技服务<br>
技术需求 <input type="radio" name="hezuomoshi" value="独立开发">独立开发
<input type="radio" name="hezuomoshi" value="技术转让">技术转让<br>
合作模式 <input type="radio" name="hezuomoshi" value="技术入股">技术入股
<br>
计划总投资:<input type="text" name="tourujin">万元
<br>
<input type ="submit" value="提交">
<input type="reset" value="重置" >
</form>
</body>
</html>
yonghuzhuce.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>注册</title>
<style>
body{text-align:center}
</style>
</head>
<body>
<form action="/Test5/r2?method=addyonghu"method="post" onsubmit="return check();">
<h1>请输入信息</h1>
1.用户名:<input type="text" name="name"> <br/>
2.密码:<input type="password" name="password" id="pwd"> <br/>
3.重复密码:<input type="password" name=password1 id="pwd1" onkeyup="checkpassword()"> <br>
4.手机号码:<input type="text" name="number" maxlength="11"> <br>
5.所属单位:<input type="text" name="danwei"><br>
<input type ="submit" value="提交">
<input type="reset" value="重置" >
</form>
</body>
<script type="text/javascript">
function checkpassword(){
var password=document.getElementById("pwd").value;
var password1=document.getElementById("pwd1").value;
alter("两次输入的密码不同");
if(password==password1)
alert("两次输入的密码不同");
}
</script>
</html>


浙公网安备 33010602011771号