首页 > 其他分享 >11.16更新2

11.16更新2

时间:2023-12-18 18:48:27浏览次数:29  
标签:String 11.16 request 更新 connection statement null id

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.*" %>

<%
request.setCharacterEncoding("UTF-8");
String id = request.getParameter("id");
String name = request.getParameter("name");
String gender = request.getParameter("gender");
String class1 = request.getParameter("class");
String major = request.getParameter("major");


// 数据库连接信息
String dbURL = "jdbc:mysql://localhost:3306/demo?useSSL=false";
String dbUsername = "root";
String dbPassword = "123456";

Connection connection = null;
PreparedStatement statement = null;
ResultSet rs = null;
try {
// 连接数据库
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(dbURL, dbUsername, dbPassword);
// 检查学生是否存在
String checkSql = "SELECT * FROM market WHERE id = ?";
PreparedStatement checkStatement = connection.prepareStatement(checkSql);
checkStatement.setString(1, id);
rs = checkStatement.executeQuery();

if (rs.next()) {
// 学生存在,更新信息
// 修改学生信息的SQL语句
String updateSql = "UPDATE market SET name = ?, gender = ?,class = ?,major = ? WHERE id = ?";
// 创建PreparedStatement对象
statement = connection.prepareStatement(updateSql);
// 设置参数值
statement.setString(1, name);
statement.setString(2, gender);
statement.setString(3, class1);
statement.setString(4, major);
statement.setString(5, id);
// 执行更新操作
int rowsAffected = statement.executeUpdate();

// 检查更新结果
if (rowsAffected > 0) {
out.println("学生信息更新成功!");
} else {
out.println("学生信息更新失败!");
}
} else {
out.println("学生不存在,无法更新信息!");
}
} catch (Exception e) {
// 处理异常情况
out.println("更新学生信息失败:" + e.getMessage());
} finally {
// 关闭ResultSet、PreparedStatement和数据库连接
if (rs != null) {
rs.close();
}
if (statement != null) {
statement.close();
}
if (connection != null) {
connection.close();
}
}
%>

标签:String,11.16,request,更新,connection,statement,null,id
From: https://www.cnblogs.com/dmx-03/p/17911920.html

相关文章

  • 更新升级 | iTOP-RK3588开发板手册分类详解
    迅为iTOP-RK3588开发板配套手册升级!因为开发资料众多(目前手册资料已达2700+页),为了方便大家更快速上手使用开发板,迅为iTOP-RK3588开发板配套手册按功能性分为了13大类,如下所示  1快速定位 每个分类下包含了对应主题的PDF文档资料,这样大家可以快读定位需要使用的文档。每个主题下......
  • 【HarmonyOS】鸿蒙应用安装三方包后,为什么每次同步更新都会将三方包更新成最新版本?
    【关键字】鸿蒙应用三方包安装,ohpm三方包安装 【问题详情】进行鸿蒙应用开发时,我们经常会通过ohpm命令安装三方包实现某些功能,但是可能会存在这种情况:当三方包发布新版本后,点击同步工程,会出现默认更新安装的三方包版本情况;但是因为功能版本兼容问题,我们往往不想升级版本,本篇......
  • 11.16
    1、项目需求:企业员工考勤管理系统是一个企业单位信息化建设不可缺少的部分。考勤管理系统是针对某公司对该公司职工的考勤、查询、信息录入、核查、统计分析等功能为一体的应用软件,为用户提供充足的信息和快捷的查询手段。 2.系统要求与功能设计2.1页面要求(1)系统可以通过浏......
  • python常用内置模块(持续更新中)
    random模块相关方法需要掌握的,未提及的建议自行了解importrandom大于0且小于1之间的小数(不含1)random.random()#0.38916016381720087指定区间指定start到end(不含end)之间的随机小数random.uniform(0,10)#8.080921224222864指定区间指定start到end(含end)之......
  • 【电子公文系统】维护和更新记录
    更新记录更新版本发布日期更新内容更新类型1.0.12023-11-15修复登录模块的安全漏洞。安全修复1.1.02023-11-20添加文档共享功能。功能添加1.1.12023-11-30优化页面设计页面优化1.2.02023-12-05更新用户界面设计。功能更新1.2.12023-12-12修......
  • offline RL | Pessimistic Bootstrapping (PBRL):在 Q 更新中惩罚 uncertainty,拉低 OOD
    论文题目:PessimisticBootstrappingforUncertainty-DrivenOfflineReinforcementLearning,ICLR2022,6688spotlight。pdf版本:https://arxiv.org/abs/2202.11566html版本:https://ar5iv.labs.arxiv.org/html/2202.11566openreview:https://openreview.net/forum?id=Y4c......
  • 好久没来了,过来更新一下
    #include<asssert.h>//kMP算法char*my_strstr(constchar*p1,constchar*p2){ assert(p1!=NULL); assert(p2!=NULL); char*s1=(char*)p1; char*s2=(char*)p2; char*cur=(char*)p1; if(!*p2) { return(char*)p1; } while(*cur) {......
  • elasticsearch 文档更新操作:update和update_by_query
    API:(elasticsearch版本7.3)POST/<index>/_update/<_id>POST/<index>/_update_by_query1.POST/<index>/_update/<_id>支持脚本,可以更新、删除或跳过修改文档。更新文档部分内容,传递部分文档,将其合并到现有文档中。#测试--post/update脚本修改文档POST/king_test_p......
  • 11.16
    今日学习内容<%@pageimport="java.sql.DriverManager"%><%@pageimport="java.sql.*"%><%--CreatedbyIntelliJIDEA.TochangethistemplateuseFile|Settings|FileTemplates.--%><%@pagecontentType="text/htm......
  • StarBlog - 2023年底更新内容一览
    前言先说一下我对StarBlog这个系列的文章的规划吧,在StarBlog的1.x版本,我会同步更新两个系列的文章博客前台+接口开发笔记(即当前已发布的这一系列文章)博客Vue后台开发笔记(后续开始持续发布)最近很久没有更新StarBlog系列的文章,事实上我之前已经把【博客Vue后台开发......