SQL -------- JDBC 修改某条记录得内容
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 修改某条记录得内容的更多相关文章
- mybatis批量更新两种方式:1.修改值全部一样 2.修改每条记录值不一样
Mybatis批量更新数据 mybatis批量更新两种方式:1.修改值全部一样 2.修改每条记录值不一样 mybatis批量更新两种方式:1.修改值全部一样 2.修改每条记录值不一样 mybatis批 ...
- salesforce 零基础学习(六十九)当新增/修改一条记录以后发生了什么(适合初学者)
salesforce开发中,我们会对object进行很多的操作,比如对object设置字段的必填性唯一性等,设置validation rule实现一下相关的字段的逻辑校验,设置workflow实现某个 ...
- Python 逐行修改txt每条记录的内容
Txt中保存以些数据,这些数据中我们要逐行read line出来进行处理,约定第一个字符为"#"的数据表示已经处理. 一个办法是读取txt,新增另外一个已完成处理txt来保存完成的 ...
- sql查询上一条记录和下一条记录
上一条记录的SQL语句: * from news where newsid<id order by newsid DESC 下一条记录的SQL语句: * from news where news ...
- SQL 从100万条记录中的到 成绩最高的记录
从100万条记录中的到 成绩最高的记录 问题分析:要从一张表中找到成绩最高的记录并不难,有很多种办法,最简单的就是利用TOP 1 select top 1 * from student order b ...
- SQL SERVER:一条SQL语句插入多条记录等
在学习排名第二的mySql过程中,发现它的插入语句可以这样写: use test; create table fruits( fid char(10) not null ,s_id int null ...
- sql中筛选第一条记录【分组排序】
问题描述 我们现在有一张表titles,共有4个字段,分别是emp_no(员工编号),title(职位),from_date(起始时间),to_date(结束时间),记录的是员工在某个时间段内职位名称 ...
- sql对每一条记录都给他一个随机的数。
update [WonyenMall].[dbo].[T_Real_Commodity] set increment=FLOOR(RAND(ABS(CHECKSUM(NEWID()))) * 100) ...
- sql中插入多条记录-微软批处理
这是使用批处理的一个例子: System.IO.StreamWriter messagelog = null; string messageString = ""; SqlConn ...
随机推荐
- Elastic-Job开发指南(转)
原文地址:http://dangdangdotcom.github.io/elastic-job/post/1.x/user_guide/ 开发指南 代码开发 作业类型 目前提供3种作业类型,分别是S ...
- Java 显示调用隐式调用
当你没有使用父类默认的构造方法时,此时在子类的构造方法中就需要显示的调用父类定义的构造方法.比如:父类:class Animal{ private String name; //如果你定义一个新的构造 ...
- WHU 583 Palindrome ( 回文自动机 && 本质不同的回文串的个数 )
题目链接 题意 : 给你一个串.要你将其划分成两个串.使得左边的串的本质不同回文子串的个数是右边串的两倍.对于每一个这样子的划分.其对答案的贡献就是左边串的长度.现在要你找出所有这样子的划分.并将贡献 ...
- 【转载】C++ STL priority_queue用法
priority_queue 对于基本类型的使用方法相对简单.他的模板声明带有三个参数,priority_queue<Type, Container, Functional> Type 为 ...
- 2019.6.20 校内测试 NOIP模拟 Day 1 分析+题解
这次是zay神仙给我们出的NOIP模拟题,不得不说好难啊QwQ,又倒数了~ T1 大美江湖 这个题是一个简单的模拟题. ----zay 唯一的坑点就是打怪的时候计算向上取整时,如果用ceil函数一 ...
- Appium基础教程
目录 Appium教程 Appium简介 App自动化测试工具对比 Appium实现原理 环境搭建 Andorid介绍 基本架构 常见布局/视图 基本控件 控件常见属性 Adb介绍 Adb常用命令 A ...
- html页面之间相互传值
常见的在页面登录过后会获得一个token值然后页面跳转时传给下一个页面 sessionStorage.setItem("token",result.token);//传输token ...
- Codeforces 1205C Palindromic Paths (交互题、DP)
题目链接 http://codeforces.com/contest/1205/problem/C 题解 菜鸡永远做着变巨的梦 然而依然连div1BC题都不会做 要是那天去打cf怕是又要1题滚粗了.. ...
- XXE_payload
<?php $xmlfile = file_get_contents('php://input'); $creds=simplexml_load_string($xmlfile); echo $ ...
- QT程序拷贝 转移 改变运行环境
qt程序 在windows平台下怎么运行? 以前开发环境是VS2008编译 +qt-win-opensource-4.7.4-vs2008框架 +QtCreator编辑界面(以前的例子,win7下成功 ...