jdbctemplate

why spring jdbcTemplate batchUpdate insert row by row

六眼飞鱼酱① 提交于 2019-11-30 14:32:22
I have 200K rows to be inserted in one single database table. I tried to use jdbcTemplate.batchUpdate in spring in order to do insertion 10,000 per batch. However, this process consumes too much time (7 mins for 200K rows). So on database side, I check the number of rows inserted by select count(*) from table_X . I found the number of rows increased slightly instaed of 10K expected. Can anyone explain what's reason or is it something which should be configurated on Database side ? PS: I am using sybase .... Sanka There are lot of approaches available on the web. Performance directly depends on

spring学习笔记(十二):使用 xml 方式实现 spring 的声明式事务管理(使用对 jdbc 的支持)

允我心安 提交于 2019-11-30 10:46:57
编程式事务管理: 自己手动控制事务,就叫做 编程式事务管理。 编程式事务管理可以清楚的定义事务的边界,可以实现细粒度的事务控制,比如可以通过代码控制事务何时开始,何时结束。 例如 jdbc、hibernate 就是编程式事务管理,spring 中不提倡使用。 jdbc 代码: conn.setAutoCommite(false); // 设置 手动控制事务 hibernate 代码: session.beginTransaction(); // 开启一个事务 细粒度 的事务控制:可以对指定的方法、或指定方法的某几行添加事务控制; 比较灵活,但开发起来比较繁琐,每次都要开启、提交、回滚。 声明式事务管理: 如果不需要细粒度的事务控制,可以使用声明式事务。 spring 中提供的对事务的管理,就叫做声明式事务管理。 只需要在 spring 配置文件中做一些配置,即可将操作纳入到事务管理中,解除了和代码的耦合。 spring 声明式事务管理,核心实现就是基于 AOP。 Spring 声明式事务管理器类: Jdbc 技术: DataSourceTransactionManager Hibernate 技术: HibernateTransactionManager 使用 xml 方式实现 spring 的声明式事务管理 需要引入 aop 名称空间 和 tx 名称空间。 DeptDao

How to set custom connection properties on DataSource in Spring Boot 1.3.x with default Tomcat connection pool

依然范特西╮ 提交于 2019-11-30 09:31:40
I need to set some specific Oracle JDBC connection properties in order to speed up batch INSERT s ( defaultBatchValue ) and mass SELECT s ( defaultRowPrefetch ). I got suggestions how to achieve this with DBCP (Thanks to M. Deinum) but I would like to: keep the default Tomcat jdbc connection pool keep application.yml for configuration I was thinking about a feature request to support spring.datasource.custom_connection_properties or similar in the future and because of this tried to pretent this was already possible. I did this by passing the relevant information while creating the DataSource

Spring学习笔记(七)

假装没事ソ 提交于 2019-11-30 09:18:53
JdbcTemplate 作用:用于和数据库交互,实现对表的CRUD操作。 Account.java package com . how2java . domain ; import java . io . Serializable ; /** * 账户的实体类 */ public class Account implements Serializable { private Integer id ; private String name ; private Float money ; public Integer getId ( ) { return id ; } public void setId ( Integer id ) { this . id = id ; } public String getName ( ) { return name ; } public void setName ( String name ) { this . name = name ; } public Float getMoney ( ) { return money ; } public void setMoney ( Float money ) { this . money = money ; } @Override public String toString ( ) {

Spring JdbcTemplate - Insert blob and return generated key

喜你入骨 提交于 2019-11-30 06:54:22
问题 From the Spring JDBC documentation, I know how to insert a blob using JdbcTemplate final File blobIn = new File("spring2004.jpg"); final InputStream blobIs = new FileInputStream(blobIn); jdbcTemplate.execute( "INSERT INTO lob_table (id, a_blob) VALUES (?, ?)", new AbstractLobCreatingPreparedStatementCallback(lobhandler) { protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException { ps.setLong(1, 1L); lobCreator.setBlobAsBinaryStream(ps, 2, blobIs, (int)blobIn

SSH框架之Spring第四篇

蓝咒 提交于 2019-11-30 06:31:11
1.1 JdbcTemplate概述 : 它是spring框架中提供的一个对象,是对原始JdbcAPI对象的简单封装.spring框架为我们提供了很多的操作模板类. ORM持久化技术 模板类 JDBC org.springframework.jdbc.core.JdbcTemplate. Hibernate3.0 org.springframework.orm.hibernate3.HibernateTemplate. IBatis(MyBatis) org.springframework.orm.ibatis.SqlMapClientTemplate. JPA org.springframework.orm.jpa.JpaTemplate. 在导包的时候需要导入spring-jdbc-4.24.RELEASF.jar,还需要导入一个spring-tx-4.2.4.RELEASE.jar(它和事务有关) <!-- 配置数据源 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"></property> <property name="url" value=

sharding-jdbc读写分离源码分析

微笑、不失礼 提交于 2019-11-30 06:23:45
sharding-jdbc读写分离源码分析 由于最近生产上单点数据库有瓶颈,准备使用读写分离来提高应用的性能,在框架调研的过程中发现当当网的开源数据库驱动框架sharding-jdbc,读写分离的功能无需修改应用的代码只需要使用xml或者配置文件配置多个数据源,一时好奇想看看是怎么实现的,起先第一步使用springboot快速搭建一个可查看源码的项目在idea新建一个maven项目并引入shardingjdbc 的jar包 pom.xml文件如下图所示 < parent > < groupId > org.springframework.boot </ groupId > < artifactId > spring-boot-starter-parent </ artifactId > < version > 1.4.6.RELEASE </ version > </ parent > < dependencies > < dependency > < groupId > org.springframework.boot </ groupId > < artifactId > spring-boot-starter-jdbc </ artifactId > </ dependency > < dependency > < groupId > mysql </ groupId > <

what is difference between ResultSetExtractor vs Rowmapper?

一笑奈何 提交于 2019-11-30 06:17:29
问题 I worked on both row mapper and resultset extractor call back interfaces.I found difference i.e., 1.Row mapper can be processing per row basis.But Resultset extractor we can naviagte all rows and return type is object. Is there any difference other than above?.How the works Rowmapper internal and return type is list?. 回答1: JavaDoc of ResultSetExtractor: This interface is mainly used within the JDBC framework itself. A RowMapper is usually a simpler choice for ResultSet processing, mapping one

JdbcTemplate IN Clause for String elements

≯℡__Kan透↙ 提交于 2019-11-30 04:55:08
问题 Am using NamedParameterJdbcTemplate for where Clause elements and one of them seems to be List<String> . JdbcTemplate replaces them ?,?,?...(list size) but for a IN clause with List<String> it has to be '?','?'.... Is there a way around this? 回答1: There a few other similar questions out there which might have helpful answers for you: How to execute IN() SQL queries with Spring's JDBCTemplate effectivly? To make this style of query work on my end, I have to switch from plain old JDBCTemplate

Unit testing a DAO class that uses Spring JDBC

微笑、不失礼 提交于 2019-11-30 03:45:12
I have several DAO objects that are used to retrieve information from a database and I really want to write some automated tests for them but I'm having a hard time figuring out how to do it. I'm using Spring's JdbcTemplate to run the actual query (via a prepared statement) and map the results to the model object (via the RowMapper class). If I were to write unit tests, I'm not sure how I would/should mock the objects. For example, since there are only reads, I would use the actual database connection and not mock the jdbcTemplate, but I'm not sure that's right. Here's the (simplified) code