Spring SimpleJdbcOperations 批量更新
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 批量更新的更多相关文章
- Spring批量更新batchUpdate提交和Hibernate批量更新executeUpdate
1:先看hibernate的批量更新处理. 版本背景:hibernate 5.0.8 applicationContext.xml 配置清单: <?xml version="1.0&q ...
- spring data jpa开启批量插入、批量更新
spring data jpa开启批量插入.批量更新 原文链接:https://www.cnblogs.com/blog5277/p/10661096.html 原文作者:博客园--曲高终和寡 *** ...
- mybatis批量更新报错 org.mybatis.spring.MyBatisSystemException
具体报错信息: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.Bin ...
- mybatis的一种批量更新方法【我】
接手一个项目,项目主要架构用的 servlet 3.0 + spring + mybatis 其中发现一个问题: 操作数据时,批量插入可以,批量更新,使用各种写法都无法成功,直接报 mybatis转换 ...
- 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 ...
- springboot 整合 mongodb实现 批量更新数据
现需求:需要批量将1000个数据先查询在更新到mongodb(如果查询不到数据,则添加数据) 1:工具类BathUpdateOptions import org.springframework.dat ...
- 【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 ...
- SpringBoot+Mybatis+Druid批量更新 multi-statement not allow异常
本文链接:https://blog.csdn.net/weixin_43947588/article/details/90109325 注:该文是本博主记录学习之用,没有太多详细的讲解,敬请谅解! ...
- Mysql批量更新的三种方式
前言 批量插入由于mysql的VALUES原生支持,使用较为便利. 批量更新的写法一般有三种,在更新数量较少的情况下,前两种性能不相上下.但是在更新字段增加,更新条数较多(500以上)建议使用第三种写 ...
随机推荐
- 【转】iphone 输入/输出流异步读写数据
原文:iphone 输入/输出流异步读写数据 分类: iphone2012-05-30 14:50 2484人阅读 评论(1) 收藏 举报 iphoneattributesinterfacepaths ...
- MVC中使用过滤器做权限认证需要注意的地方
最近一项目接近尾声,正准备调试的时候发现一条原本不应该执行的SQL语句执行报错了,本就不应该执行,所以当然也就出错,找了一下,问题如下. 我这里是直接重写OnActionExecuting方法来达到目 ...
- myeclipse run按钮不见了
window-->new window,打开新窗口,按钮出现了.关闭老窗口,再关闭新窗口.再次打开MyEclipse,妥妥的了.
- python 中logging的日志封装
因为最近在做平台,发现有同事,使用django封装了日志模块,看样子很简单,准备自己单独做了一个日志封装模板,对于python不熟练的我,封装部分参考了多个博主的内容,形成自己的日志模块,内容如下: ...
- Spring Security 自定义配置(1)
@Configuration @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapte ...
- Eclipse导入web项目发布项目时报Tomcat version 7.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 and 6 Web错误解决方案
Eclipse导入web项目后,将web项目加载到server进行发布时,提示Tomcat version 7.0 only supports J2EE 1.2, 1.3, 1.4, and Java ...
- 转载:monkeyrunner之eclipse中运行monkeyrunner脚本之环境搭建(四)
转载自:lynnLi 的monkeyrunner之eclipse中运行monkeyrunner脚本之环境搭建(四) monkeyrunner脚本使用Python语法编写,但它实际上是通过Jython来 ...
- max函数
无论是几维,都只返回一个最大的值 >>> a = [1,2,3] >>> np.max(a) 3 >>> a = [[2,1],[3,4]] &g ...
- VPP(Vector Packet Processing)配置工具
前言 VPP提供了一个配置工具,让用户可以简单快捷地配置VPP.用户可以通过一些简单的命令配置VPP,功能包括安装及一些基本配置和测试用例. 使用 先安装一个python的pip模块,使用pip安装V ...
- Laravel发送邮件配置-问题解决
MAIL_DRIVER=smtp MAIL_HOST=smtp..com MAIL_PORT= MAIL_USERNAME=phpfangzhan@@@@@.com MAIL_PASSWORD=*** ...