package demo;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement; import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; /**
* Servlet implementation class UpdateCustomer
*/
@WebServlet("/updateCustomer.do")
public class UpdateCustomer extends HttpServlet {
private static final long serialVersionUID = 1L; /**
* @see HttpServlet#HttpServlet()
*/
public UpdateCustomer() {
super();
// TODO Auto-generated constructor stub
} /**
* @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
*/
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //获取修改后的参数
String CustomerID =request.getParameter("CustomerID");
String CustomerName = request.getParameter("CustomerName");
String ContactName= request.getParameter("ContactName");
String Address = request.getParameter("Address");
String City = request.getParameter("City");
String PostalCode = request.getParameter("PostalCode");
String Country=request.getParameter("Country"); //设置数据库连接参数
String url="jdbc:mysql://localhost:3306/库名?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT";
String user = "用户名";
String password="密码"; //加载数据库驱动
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try(Connection connection =DriverManager.getConnection(url, user, password)){//连接数据库
//where指定条件
//修改sql语句,customers为表名
String sql = "update Customers set CustomerName=?, ContactName=?, Address=?,City=?, PostalCode=?,Country=? where customerID=?;";
PreparedStatement statement = connection.prepareStatement(sql);//预处理sql语句
//以下语句对应VALUES语句里的值
statement.setString(1, CustomerName);
statement.setString(2, ContactName);
statement.setString(3, Address);
statement.setString(4, City);
statement.setString(5, PostalCode);
statement.setString(6, Country);
statement.setInt(7, Integer.parseInt(CustomerID));
int value = statement.executeUpdate();//executeUpdate执行修改,将修改的个数传给value statement.close();// 关闭statement,释资源 }catch(SQLException e) {
e.printStackTrace();
}
request.getRequestDispatcher("queryalldata.jsp").forward(request, response);//跳转到查询所有得服务程序
} }

SQL -------- JDBC 修改某条记录得内容的更多相关文章

  1. mybatis批量更新两种方式:1.修改值全部一样 2.修改每条记录值不一样

    Mybatis批量更新数据 mybatis批量更新两种方式:1.修改值全部一样 2.修改每条记录值不一样 mybatis批量更新两种方式:1.修改值全部一样 2.修改每条记录值不一样 mybatis批 ...

  2. salesforce 零基础学习(六十九)当新增/修改一条记录以后发生了什么(适合初学者)

    salesforce开发中,我们会对object进行很多的操作,比如对object设置字段的必填性唯一性等,设置validation rule实现一下相关的字段的逻辑校验,设置workflow实现某个 ...

  3. Python 逐行修改txt每条记录的内容

    Txt中保存以些数据,这些数据中我们要逐行read line出来进行处理,约定第一个字符为"#"的数据表示已经处理. 一个办法是读取txt,新增另外一个已完成处理txt来保存完成的 ...

  4. sql查询上一条记录和下一条记录

    上一条记录的SQL语句: * from news where newsid<id order by newsid DESC 下一条记录的SQL语句: * from news where news ...

  5. SQL 从100万条记录中的到 成绩最高的记录

    从100万条记录中的到 成绩最高的记录 问题分析:要从一张表中找到成绩最高的记录并不难,有很多种办法,最简单的就是利用TOP 1 select top 1 * from student order b ...

  6. SQL SERVER:一条SQL语句插入多条记录等

    在学习排名第二的mySql过程中,发现它的插入语句可以这样写: use test; create table fruits( fid char(10) not null ,s_id int null ...

  7. sql中筛选第一条记录【分组排序】

    问题描述 我们现在有一张表titles,共有4个字段,分别是emp_no(员工编号),title(职位),from_date(起始时间),to_date(结束时间),记录的是员工在某个时间段内职位名称 ...

  8. sql对每一条记录都给他一个随机的数。

    update [WonyenMall].[dbo].[T_Real_Commodity] set increment=FLOOR(RAND(ABS(CHECKSUM(NEWID()))) * 100) ...

  9. sql中插入多条记录-微软批处理

    这是使用批处理的一个例子: System.IO.StreamWriter messagelog = null; string messageString = ""; SqlConn ...

随机推荐

  1. C++头文件中#pragma once与#ifndef……#define……#endif

    两者功能一样,防止重复包含被多次编译.建议头文件加入#pragma once C++头文件开头的两句与结尾的一句#ifndef <标识>#define <标识>类代码#endi ...

  2. 并发编程入门(一): POSIX 使用互斥量和条件变量实现生产者/消费者问题

    boost的mutex,condition_variable非常好用.但是在Linux上,boost实际上做的是对pthread_mutex_t和pthread_cond_t的一系列的封装.因此通过对 ...

  3. Gym 100548F Color 给花染色 容斥+组合数学+逆元 铜牌题

    Problem F. ColorDescriptionRecently, Mr. Big recieved n flowers from his fans. He wants to recolor th ...

  4. 2019ICPC陕西邀请赛复盘

    题目链接:The 2019 ACM-ICPC China Shannxi Provincial Programming Contest A:签到,按花费时间从小到大排个序 #include<cs ...

  5. 第三方库requests详解

    Requests 是用Python语言编写,基于 urllib,采用 Apache2 Licensed 开源协议的 HTTP 库.它比 urllib 更加方便,可以节约我们大量的工作,完全满足 HTT ...

  6. Ranorex连接Android

    开始在Android上进行移动测试 只需按照下面的步骤开始使用Android进行移动测试. 1.连接设备(USB/Wi-Fi) 2.在Ranorex中添加设备 3.将设备名称设置为参数值 4.运行示例 ...

  7. LeetCode 无重复字符的最长子串(探索字节跳动)

    题目描述 给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度. 示例 1: 输入: "abcabcbb" 输出: 3 解释: 因为无重复字符的最长子串是 "a ...

  8. Flume-Exec Source 监控单个本地文件

    实时监控,并上传到 HDFS 中. 一.Flume 要想将数据输出到 HDFS,须持有 Hadoop 相关 jar 包 若 Hadoop 环境和 Flume 在同一节点,那么只要配置 Hadoop 环 ...

  9. Nginx在Linux安装详解及问题处理

    Linux编译安装 1.nginx 依赖于prce库,要先安装pcre. #yum install prce pcre-devel 2.下载解压nginx #cd /usr/local/src/ #w ...

  10. Appnium安装

    Refer to https://blog.csdn.net/xgh1951/article/details/85124327