1.控制台代码

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcOperations;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.dao.DataAccessException;
import java.sql.*; public class MySQL { public static void main(String[] args) {
org.logicalcobwebs.proxool.ProxoolDataSource ds = new org.logicalcobwebs.proxool.ProxoolDataSource();
ds.setDriver("com.mysql.jdbc.Driver");
ds.setDriverUrl("jdbc:mysql://192.168.1.49/test?useUnicode=true&characterEncoding=gbk&zeroDateTimeBehavior=convertToNull");
ds.setUser("test");
ds.setPassword("123456");
ds.setTestBeforeUse(true);
ds.setTrace(true);
ds.setHouseKeepingTestSql("select 1"); String sql = "insert into Goods(id,good_name) values(:id,:good_name)"; Goods obj = new Goods();
obj.setId(7);
obj.setGood_name("yes3"); Goods obj2 = new Goods();
obj2.setId(6);
obj2.setGood_name("yes2");
SimpleJdbcOperations m = new SimpleJdbcTemplate(ds); SqlParameterSource[] params = new SqlParameterSource[2];
params[0] = new BeanPropertySqlParameterSource(obj);
params[1] = new BeanPropertySqlParameterSource(obj2);
m.batchUpdate(sql, params); // m.getNamedParameterJdbcOperations().update(sql,
// new BeanPropertySqlParameterSource(obj)); // Connection con= ds.getConnection();
// Statement stmt=con.createStatement();
// stmt.executeUpdate("insert into Goods(id,good_name) values(1,'niunai')");
// con.close(); } }

2.实体类

import java.io.Serializable;

public class Goods implements Serializable {

    private static final long serialVersionUID = 5951566786306525049L;
private int id;
/**
* @return the id
*/
public int getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(int id) {
this.id = id;
}
/**
* @return the good_name
*/
public String getGood_name() {
return good_name;
}
/**
* @param good_name the good_name to set
*/
public void setGood_name(String good_name) {
this.good_name = good_name;
}
private String good_name;
}

3.数据库

create table Goods
(
id int ,
good_name varchar(20)
)

4.需要的jar文件

org.springframework.jdbc-3.0.3.RELEASE.jar
proxool-cglib.jar
proxool-0.9.1.jar
commons-logging-1.1.1.jar
log4j-1.2.16.jar
org.springframework.context-3.0.3.RELEASE.jar
org.springframework.context.support-3.0.3.RELEASE.jar
org.springframework.beans-3.0.3.RELEASE.jar
org.springframework.aspects-3.0.3.RELEASE.jar
org.springframework.asm-3.0.3.RELEASE.jar
org.springframework.aop-3.0.3.RELEASE.jar
org.springframework.expression-3.0.3.RELEASE.jar
org.springframework.transaction-3.0.3.RELEASE.jar
mysql-connector-java-5.1.15-bin.jar

Spring SimpleJdbcOperations 批量更新的更多相关文章

  1. Spring批量更新batchUpdate提交和Hibernate批量更新executeUpdate

    1:先看hibernate的批量更新处理. 版本背景:hibernate 5.0.8 applicationContext.xml 配置清单: <?xml version="1.0&q ...

  2. spring data jpa开启批量插入、批量更新

    spring data jpa开启批量插入.批量更新 原文链接:https://www.cnblogs.com/blog5277/p/10661096.html 原文作者:博客园--曲高终和寡 *** ...

  3. mybatis批量更新报错 org.mybatis.spring.MyBatisSystemException

    具体报错信息: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.Bin ...

  4. mybatis的一种批量更新方法【我】

    接手一个项目,项目主要架构用的 servlet 3.0 + spring + mybatis 其中发现一个问题: 操作数据时,批量插入可以,批量更新,使用各种写法都无法成功,直接报 mybatis转换 ...

  5. mybatis批量更新update-设置多个字段值 报错 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near

    mybatis批量更新update-设置多个字段值 2016年08月01日 12:49:26 姚一号 阅读数:29539 标签: mysql mybatis批量更新批量更新allowMultiQuer ...

  6. springboot 整合 mongodb实现 批量更新数据

    现需求:需要批量将1000个数据先查询在更新到mongodb(如果查询不到数据,则添加数据) 1:工具类BathUpdateOptions import org.springframework.dat ...

  7. 【mybatis】mybatis进行批量更新,报错:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right

    使用mybatis进行批量更新操作: 报错如下: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an erro ...

  8. SpringBoot+Mybatis+Druid批量更新 multi-statement not allow异常

      本文链接:https://blog.csdn.net/weixin_43947588/article/details/90109325 注:该文是本博主记录学习之用,没有太多详细的讲解,敬请谅解! ...

  9. Mysql批量更新的三种方式

    前言 批量插入由于mysql的VALUES原生支持,使用较为便利. 批量更新的写法一般有三种,在更新数量较少的情况下,前两种性能不相上下.但是在更新字段增加,更新条数较多(500以上)建议使用第三种写 ...

随机推荐

  1. linux性能系列--cpu

    一.先看看什么是CPU? 回答:中央处理器(Central Processing Unit)的缩写,即CPU,CPU是电脑中的核心配件,只有火柴盒那么大,几十张纸那么厚,但它却是一台计算机的运算核心和 ...

  2. Access用OleDbParameter无法更新数据解决方案

    昨天遇到了一个非常郁闷的问题,这个问题我几乎花了一天的时间才找到了造成问题的症结并解决. 问题是这样,原本一个使用Sqlserver数 据库的系统,我要让它实现Access数据接口,即我可以很方便地把 ...

  3. TreadingTCPServer

    TreadingTCPServer实现的socket服务器内部会为每个client创建一个线程,该线程用来和客户端进行交互. 1.TreadingTCPServer基础 使用TreadingTCPSe ...

  4. c++ 派生类的构造函数次序

    #include <iostream> using namespace std; class CFatherSum //父类Sum { public: CFatherSum(int iRe ...

  5. 【[NOI2010]航空管制】

    关于拓扑排序的反建图还是一个非常套路的东西 比如说[HNOI2015]菜肴制作 我们希望使得某一个东西在拓扑序中出现的尽可能早,这个时候就可以建出一张反图来,使得这个东西在反图中的拓扑序尽量靠后,从而 ...

  6. POJ3347 Kadj Squares

    嘟嘟嘟 题意:给出一堆正方形的边长,且这些正方形都是\(45 ^ {\circ}\)斜放着并且紧挨着的,求从上往下看能看到几个正方形. 真是一道好题--跟计算几何关系不大. 想一下,如果我们能求出正方 ...

  7. SwaggerUI用户手册

    SwaggerUI是一个非常好用的API文档工具,最关键的是他还能在工具内调试API,简直爽的不要不要的~网上针对开发者的文档非常多,但是给用户的手册却非常少.所以我来简单写个用户手册,供没有使用过s ...

  8. Observer(观察者)模式

    1.概述 一些面向对象的编程方式,提供了一种构建对象间复杂网络互连的能力.当对象们连接在一起时,它们就可以相互提供服务和信息. 通常来说,当某个对象的状态发生改变时,你仍然需要对象之间能互相通信.但是 ...

  9. SpringMVC中controller的几种返回值

    String :跳转到对应的返回值中. return “/index”: ModelAndView: 控制页面跳转方式: 1. ModelAndView modelAndView = new Mode ...

  10. linux 进程间通信方式

    管道: 它包括无名管道和有名管道两种,前者用于父进程和子进程间的通信,后者用于运行于同一台机器上的任意两个进程间的通信消息队列: 用于运行于同一台机器上的进程间通信,它和管道很相似,是一个在系统内核中 ...