首页 > 其他分享 >小学期第三次博客--实现代码如下

小学期第三次博客--实现代码如下

时间:2024-07-20 20:20:36浏览次数:13  
标签:第三次 -- novelty request getParameter stmt 博客 document String

package com.example.hadoop;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class HiveJdbcUtils {
    private static final String URL = "jdbc:hive2://192.168.26.2:10000/testforhadoop";
    private static final String USER = "hadoop";
    private static final String PASSWORD = "123456";


    static {
        try {
            Class.forName("org.apache.hive.jdbc.HiveDriver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static Connection getConnection() throws SQLException {
        return DriverManager.getConnection(URL, USER, PASSWORD);
    }
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title>添加项目查新信息</title>
    <script type="text/javascript">
        function toggleSelects() {
            var immediate = document.getElementById('immediate_select');
            var achievement = document.getElementById('achievement_select');
            var other = document.getElementById('other_select');
            immediate.style.display = 'none';
            achievement.style.display = 'none';
            other.style.display = 'none';

            if (document.getElementById('immediate_radio').checked) {
                immediate.style.display = 'block';
            } else if (document.getElementById('achievement_radio').checked) {
                achievement.style.display = 'block';
            } else if (document.getElementById('other_radio').checked) {
                other.style.display = 'block';
            }
        }

        function generateInputFields() {
            var numberOfPoints = document.getElementById('number_of_novelty_points').value;
            var container = document.getElementById('novelty_points_container');
            container.innerHTML = '';
            for (var i = 0; i < numberOfPoints; i++) {
                var input = document.createElement('input');
                input.type = 'text';
                input.name = 'novelty_point_' + (i + 1);
                input.placeholder = '查新点 ' + (i + 1);
                container.appendChild(input);
                container.appendChild(document.createElement('br'));
            }
        }

        function collectNoveltyPoints() {
            var numberOfPoints = document.getElementById('number_of_novelty_points').value;
            var allPoints = [];
            for (var i = 0; i < numberOfPoints; i++) {
                var point = document.getElementsByName('novelty_point_' + (i + 1))[0].value;
                allPoints.push(point);
            }
            document.getElementById('column_name').value = allPoints.join(';');
        }
    </script>
</head>
<body>
<h1>添加项目查新信息</h1>
<form action="AddProjectServlet" method="post" onsubmit="collectNoveltyPoints()">
    <label for="id">编号:</label>
    <input type="text" id="id" name="id"><br><br>

    <label for="project_name">项目名称:</label>
    <input type="text" id="project_name" name="project_name"><br><br>

    <label for="novelty_scope">查新范围:</label>
    <input type="checkbox" id="domestic" name="novelty_scope" value="国内"> 国内
    <input type="checkbox" id="international" name="novelty_scope" value="国外"> 国外<br><br>

    <label for="novelty_purpose">查新目的:</label><br>
    <input type="radio" id="immediate_radio" name="novelty_purpose" value="immediate" onclick="toggleSelects()"> 立即查新
    <input type="radio" id="achievement_radio" name="novelty_purpose" value="achievement" onclick="toggleSelects()"> 成果查新
    <input type="radio" id="other_radio" name="novelty_purpose" value="other" onclick="toggleSelects()"> 其他查新<br><br>

    <div id="immediate_select" style="display:none;">
        <label for="novelty_purpose_immediate">立即查新目的:</label>
        <select id="immediate" name="novelty_purpose_immediate">
            <option value="项目申报(国家级、省部级、学协会、其他)">项目申报(国家级、省部级、学协会、其他)</option>
            <option value="中小企业创新基金(研发阶段、小试-中试、市场推广)">中小企业创新基金(研发阶段、小试-中试、市场推广)</option>
            <option value="新产品">新产品</option>
            <option value="技术引进">技术引进</option>
            <option value="技术吸收与创新">技术吸收与创新</option>
            <option value="其他">其他</option>
        </select><br><br>
    </div>

    <div id="achievement_select" style="display:none;">
        <label for="novelty_purpose_achievement">成果查新目的:</label>
        <select id="achievement" name="novelty_purpose_achievement">
            <option value="成果鉴定">成果鉴定</option>
            <option value="高新技术成果转化">高新技术成果转化</option>
            <option value="申报奖励(国家级、省部级、学协会、其他奖励)">申报奖励(国家级、省部级、学协会、其他奖励)</option>
            <option value="高新技术企业认定">高新技术企业认定</option>
            <option value="其他">其他</option>
        </select><br><br>
    </div>

    <div id="other_select" style="display:none;">
        <label for="novelty_purpose_other">其他查新目的:</label>
        <select id="other" name="novelty_purpose_other">
            <option value="博士论文开题">博士论文开题</option>
            <option value="申报专利">申报专利</option>
            <option value="其他">其他</option>
        </select><br><br>
    </div>

    <label for="technical_points">技术要点:</label><br>
    <textarea id="technical_points" name="technical_points" rows="4" cols="50"></textarea><br><br>

    <label for="number_of_novelty_points">查新点个数:</label>
    <input type="number" id="number_of_novelty_points" name="number_of_novelty_points" onchange="generateInputFields()"><br><br>

    <div id="novelty_points_container"></div>

    <input type="hidden" id="column_name" name="column_name">

    <label for="search_terms">检索词:</label>
    <input type="text" id="search_terms" name="search_terms"><br><br>

    <label for="completion_date">完成时间:</label>
    <input type="date" id="completion_date" name="completion_date"><br><br>

    <label for="discipline_classification">学科分类:</label>
    <select id="discipline_classification" name="discipline_classification">
        <option value="信息科学与系统科学">信息科学与系统科学</option>
        <option value="生物学">生物学</option>
        <option value="力学">力学</option>
        <option value="物理学">物理学</option>
        <option value="化学">化学</option>
        <option value="数学">数学</option>
        <option value="天文学">天文学</option>
        <option value="地球科学">地球科学</option>
        <option value="其他">其他</option>
    </select><br><br>

    <label for="industry_classification">产业分类:</label>
    <select id="industry_classification" name="industry_classification">
        <option value="节能环保产业">节能环保产业</option>
        <option value="生物产业">生物产业</option>
        <option value="新一代信息技术产业">新一代信息技术产业</option>
        <option value="高端装备制造产业">高端装备制造产业</option>
        <option value="新能源产业">新能源产业</option>
        <option value="新材料产业">新材料产业</option>
        <option value="新能源汽车">新能源汽车</option>
        <option value="国民经济其他产业">国民经济其他产业</option>
    </select><br><br>

    <label for="remarks">备注:</label><br>
    <textarea id="remarks" name="remarks" rows="4" cols="50"></textarea><br><br>

    <input type="submit" value="提交">
</form>
</body>
</html>
package com.example.hadoop;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/AddProjectServlet")
public class AddProjectServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");

        String id = request.getParameter("id");
        String projectName = request.getParameter("project_name");
        String noveltyScope = request.getParameter("novelty_scope");
        String noveltyPurpose = request.getParameter("novelty_purpose_immediate");
        if (noveltyPurpose == null || noveltyPurpose.isEmpty()) {
            noveltyPurpose = request.getParameter("novelty_purpose_achievement");
        }
        if (noveltyPurpose == null || noveltyPurpose.isEmpty()) {
            noveltyPurpose = request.getParameter("novelty_purpose_other");
        }
        String technicalPoints = request.getParameter("technical_points");
        int numberOfNoveltyPoints = Integer.parseInt(request.getParameter("number_of_novelty_points"));
        String columnName = request.getParameter("column_name");
        String searchTerms = request.getParameter("search_terms");
        String completionDate = request.getParameter("completion_date");
        String disciplineClassification = request.getParameter("discipline_classification");
        String industryClassification = request.getParameter("industry_classification");
        String remarks = request.getParameter("remarks");

        Connection conn = null;
        PreparedStatement stmt = null;

        try {
            conn = HiveJdbcUtils.getConnection();

            String sql = "INSERT INTO ProjectNoveltyCheck (id, project_name, novelty_scope, novelty_purpose, technical_points, number_of_novelty_points, search_terms, completion_date, discipline_classification, industry_classification, remarks, column_name) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
            stmt = conn.prepareStatement(sql);
            stmt.setString(1, id);
            stmt.setString(2, projectName);
            stmt.setString(3, noveltyScope);
            stmt.setString(4, noveltyPurpose);
            stmt.setString(5, technicalPoints);
            stmt.setInt(6, numberOfNoveltyPoints);
            stmt.setString(7, searchTerms);
            stmt.setString(8, completionDate);
            stmt.setString(9, disciplineClassification);
            stmt.setString(10, industryClassification);
            stmt.setString(11, remarks);
            stmt.setString(12, columnName);  // 设置 column_name 字段

            stmt.executeUpdate();

            response.getWriter().println("数据已成功插入!");

        } catch (SQLException e) {
            e.printStackTrace();
            response.getWriter().println("数据插入失败: " + e.getMessage());
        } finally {
            try {
                if (stmt != null) stmt.close();
                if (conn != null) conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

标签:第三次,--,novelty,request,getParameter,stmt,博客,document,String
From: https://www.cnblogs.com/muzhaodi/p/18313703

相关文章

  • 第三周学习报告
    又经过了一周的学习,今天对本周学习进行总结本周学习了Java中数组、方法的相关知识。数组数组的定义格式一:数据类型[]数组名;格式二:数据类型数组名[];静态初始化在声明数组的同时,就为数组的每个元素分配初始值。数据类型[]数组名=new数据类型[]{元素一、元素二...};简化......
  • CNE-SUE论文阅读笔记
    NeuralNewsRecommendationwithCollaborativeNewsEncodingandStructuralUserEncoding论文阅读笔记Abstract存在的问题:​ 现有的研究通常将新闻标题和内容分开编码,而忽略了它们之间的语义交互,这对于新闻文本的理解是不够的。此外,以往的模型只对用户的浏览历史进行编码,......
  • $NOI2024$游记
    day-?~day-?考了期末考后打省队集训,刚开始打的很差,bai了几天状态恢复。打进前4了,好吃捏。$day-1$报道日,育才宿舍真难泵,真独立卫浴,全是蚊子受不了,想不通育才学生一间住八个人怎么活下去的(。育才辣椒不辣,开心!没洗澡,不嘻嘻。day0今年竟是NOI四十周年,dzd英雄人物上位救赎ccf(bu......
  • 苍穹外卖学习笔记——第十二天
    数据统计(Excel报表)工作台需求分析和设计工作台是系统运营的数据看板,并提供快捷操作入口,可以有效提高商家的工作效率。产品原型工作台展示的数据今日数据订单管理菜品总览套餐总览订单信息名词解释营业额:已完成订单的总金额。有效订单:已完成订单的数量。订单完成......
  • [SDOI2011] 拦截导弹
    这是CDQ分治优化1D/1D动态规划的模板题(1D/1D动态规划的概念见OI-wiki)一般来说,优化的1D/1D/动态规划,在转移的时候是由不等式作为条件的,所以可以像这样转化为三维偏序用线段树进行如下维护:1.维护区间最大值2.查询区间最大值的某一数组的和代码见下(一定要学会将数组翻转的操作)#......
  • Day44.库的增删改查
    1.库的增删改查_数据库新增命令 #?增:createdatabase数据库名称; 2.库的增删改查_数据库新增命令并指定编码#?createdatabase数据库名称charset='指定编码';3.库的增删改查_查询所有库和查询单个库#?查:showdatabases;#查所有......
  • python 复制 excel 保留文档中完全相同的参数(样式、单元格大小和融合、边框...)
    我正在寻找一种在其他文件中复制和excel的方法。我有一个“file_1.xlsx”,但我想要一个不存在的“file_1_copy.xlsx”。副本必须与原始文件完全相同,这意味着单元格大小、它们的融合、单元格中文本的颜色、背景、如果有边框,就好像我用右键单击。我有:importopenpyxlfromope......
  • iptables 的 --syn 参数用于检测新链接
    iptables命令中的--syn参数用于匹配TCP数据包的SYN标志位。SYN是TCP协议中的一个标志,用于初始化连接的建立过程。在TCP三次握手的第一步中,客户端发送一个带有SYN标志的数据包来请求建立连接。使用--syn参数的含义--syn参数:这个参数用于在iptables规则中匹......
  • IDA Pro 8.3安装keypatch插件--odulenotfounderror: no module named 'keystone'
    按照这位博主的方法弄,一般没什么问题。http://t.csdnimg.cn/oepIT附上keypatch.py文件下载地址>https://github.com/keystone-engine/keypatch我是弄了之后发现还是报错,几经尝试,想到我有两个python环境,虽然确实是在ida使用的python环境下安装的,但是我没有指定路径,也许有......
  • 暑假第三周总结(7.15-7.20)
    这周做了什么继续学习JAVA,做出了城堡游戏点击查看代码//RoompackagecastleV3;importjava.util.HashMap;publicclassRoom{ privateStringdescription;privateHashMap<String,Room>exits=newHashMap<String,Room>();publicRoom(String......