spring-jdbc

How can I get a spring JdbcTemplate to read_uncommitted?

拈花ヽ惹草 提交于 2019-12-23 01:37:27
问题 Firstly, I can't use the declarative @Transactional approach as the application has multiple JDBC data-sources, I don't want to bore with the details, but suffice it to say the DAO method is passed the correct data-source to perform the logic. All JDBC data sources have the same schema, they're separated as I'm exposing rest services for an ERP system. Due to this legacy system there are a lot of long lived locked records which I do not have control over, so I want dirty reads. Using JDBC I

Spring-boot + JDBC + HSQLDB: How to Verify if Spring Boot is using a Connection Pool?

拟墨画扇 提交于 2019-12-22 17:55:26
问题 According to this documentation: 29.1.1 Embedded Database Support Spring Boot can auto-configure embedded H2, HSQL and Derby databases. You don’t need to provide any connection URLs, simply include a build dependency to the embedded database that you want to use. and 29.1.2 Connection to a production database Production database connections can also be auto-configured using a pooling DataSource. DataSource configuration is controlled by external configuration properties in spring.datasource.*

Lock and Isolation for resource reservation pattern

让人想犯罪 __ 提交于 2019-12-22 10:37:47
问题 I need to solve a resource reservation pattern with Spring and MariaDB. The problem is very simple, I have a guest table where I store guest names of events, I have to be sure that the guest count for the event must be less or equals the maximum capacity. This is the table: create table guest( event int, name varchar(50) ) create index event on guest (event); What is the right lock procedure and isolation level for DB? Please consider that this code will run in multi-threading container. I

Stored Procedure returning multiple tables to spring jdbc template

吃可爱长大的小学妹 提交于 2019-12-22 08:38:15
问题 Iam calling a stored procedure from my Spring DAO class using JdbcTemplate. My problem is that, stored procedure returns multiple tables. Is there a way to access multiple tables using Spring JdbcTemplate. If I use jdbcTemplate.queryForList(myStoredProc, new Object[]{parameters} iam getting only first table from the result. My database is SQL Server 2005. Is there any method other than jdbcTemplate for my requirement. If yes, please let me know. Thanks in advance.... 回答1: See http://static

Different ways of performing bulk insert into database from a java application

南楼画角 提交于 2019-12-22 06:48:27
问题 I am looking for different ways of performing bulk insert into database (e.g. SQL Server 2012) from a Java application. I need to insert lot of entities into database very efficiently without making as many calls to database as there are entities. My requirement is to perform a bulk insert of entities, where an insert of entity in database could involve inserting data into one or more tables. The following are the two ways which I can think of: Dynamically generate a batch of SQL statements

How to get inserted id using Spring Jdbctemplate.update(String sql, obj…args)

和自甴很熟 提交于 2019-12-22 06:07:09
问题 I'm using Jdbctemplate and I need the inserted id of a query. I read that I have to build a particular PreparedStatement and use GeneratedKeyHolder object. The problem is that in my application all inserts method uses this JdbcTemplate update method: getJdbcTemplate().update(SQL_INSERT,param1,param2,param3,...); Is there another way to get the inserted id without refactoring all daos? 回答1: Looking at the documentation for NamedParameterJdbcTemplate and JdbcTemplate You have two choices: use

JdbcTemplate multiple result sets

烂漫一生 提交于 2019-12-22 04:43:38
问题 I am trying to find an easy way to deal with Stored Procedures / SQL returning multiple result sets. I have been using the SimpleJdbcOperations#queryForList() method however this will only return the first result set as a List<Map<String, Object>> . I need to be able to get multiple result sets, ideally as a Collection of List<Map<String, Object>> or something. The program I am writing is a middleware component so I don't know what the SQL will be, or the form of the result set. I think I

How to preinitialize DBCP connection pool on startup?

血红的双手。 提交于 2019-12-21 17:29:12
问题 The setup of my project is - Spring JDBC for persistence Apache DBCP 1.4 for connection pooling Mysql 5 on Linux Here is the log of my application that captures the interactions with the database. 2013-01-29 15:52:21,549 DEBUG http-bio-8080-exec-3 org.springframework.jdbc.core.JdbcTemplate - Executing SQL query [SELECT id from emp] 2013-01-29 15:52:21,558 DEBUG http-bio-8080-exec-3 org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource 2013-01-29 15:52

How to change Spring to use Datasource from Tomcat vs BasicDataSource?

这一生的挚爱 提交于 2019-12-21 06:26:48
问题 How to change Spring to use Datasource from Tomcat vs BasicDataSource? below is a copy of the bean I make in my XML. Can someone tell me how to access the tomcat datasource <beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" > <beans:property name="driverClassName" value="${database.driver}" /> <beans:property name="url" value="${database.url}" /> <beans:property name="username" value="${database.user}" /> <beans:property name="password" value="${database.password}" />

Stream closeable resource with Spring MVC

℡╲_俬逩灬. 提交于 2019-12-21 05:06:25
问题 After having read this article, I wish to use Spring to stream database query results directly to a JSON response to ensure constant-memory usage (no greedy loading of a List in memory). Similar to what is done in the article with Hibernate, I assembled a greetingRepository object which returns a stream of the database contents based on a JdbcTemplate . In that implementation, I create an iterator over the queried ResultSet , and I return the stream as follows: return StreamSupport.stream