spring-jdbc

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

 ̄綄美尐妖づ 提交于 2019-12-06 13:54:44
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.*. For example, you might declare the following section in application.properties: spring.datasource

Dynamic datasource routing - DataSource router not initialized

蹲街弑〆低调 提交于 2019-12-06 10:15:31
问题 I'm referring to this article, in which we can use the AbstractRoutingDataSource from Spring Framework to dynamically change the data source used by the application. I'm using Mybatis (3.3.0) with Spring (4.1.6.RELEASE). I want to switch to the backup database if exception occurs while getting data from main db. In this example, i have used hsql and mysql db. RoutingDataSource : public class RoutingDataSource extends AbstractRoutingDataSource { @Override protected Object

Using spring-security: WebSecurityConfigurerAdapter: auth.jdbcAuthentication().usersByUsernameQuery: what should the query string look like?

别说谁变了你拦得住时间么 提交于 2019-12-06 10:09:03
问题 Using postgresql db with two tables to authenticate login ...(users and authorities) CREATE TABLE users ( username character(50) NOT NULL, password character(50) NOT NULL, enabled boolean NOT NULL, CONSTRAINT users_pkey PRIMARY KEY (username) ) CREATE TABLE authorities ( username character(50) NOT NULL, authority character(50) NOT NULL, CONSTRAINT fk_authorities_users FOREIGN KEY (username) REFERENCES users (username) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION ) What am I doing

Stored Procedure returning multiple tables to spring jdbc template

杀马特。学长 韩版系。学妹 提交于 2019-12-06 04:01:18
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.... See http://static.springsource.org/spring/docs/2.0.7/reference/jdbc.html#jdbc-StoredProcedure The example given in this section

Spring ResultSetExtractor

爱⌒轻易说出口 提交于 2019-12-06 01:49:34
问题 How to use ResultSetExtractor to retrieve data from database? here I am using oracle 10g as back end. In case of searching an Employee details from Employee Table which one is better to use ResultSetExtractor or RowMapper ? 回答1: One can also use closures (lambdas) as row mapping routine since java 8: String sql = "select first_name, last_name from PERSON where id = ?"; public Person jdbcTemplate.query(sql,(rs)->{return new Person(rs.getString("first_name"), rs.getString("last_name"));}, int

parameterized IN clause using multiple columns

你离开我真会死。 提交于 2019-12-05 22:16:23
问题 I have a query along these lines, where I am trying to filter the result set by comparing tuples (like SQL multiple columns in IN clause): select * from mytable where (key, value) in (values ('key1', 'value1'), ('key2', 'value2'), ... ); This is valid syntax and works fine on my Postgres 9.3 database. I want to invoke this query through Spring JDBC where the in value pairs come from a List<Map<String,String>> . It would be nice to do something like this: List<Map<String, String>> valuesMap =

Method not being intercepted by transaction advisor even though “adding transactional method” seen in logs

南楼画角 提交于 2019-12-05 11:48:01
I have a @Transactional @Controller , but its methods are being invoked by the Spring MVC framework without a transaction. In the exception trace I do not find the transaction advisor intercepting the call: org.hibernate.HibernateException: No Session found for current thread org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:106) org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1014) org.example.businesslogic.MyController.userLoggedIn(SwiperRest.java:48) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

APPARENT DEADLOCK c3p0 0.9.5.1 spring

让人想犯罪 __ 提交于 2019-12-05 11:22:18
We are facing APPARENT DEADLOCK while using c3p0 0.9.5.1 ( which is latest version of c3p0). following is the connection pool config we are using. p:driverClass="${app.jdbc.driverClassReplica}" p:jdbcUrl="jdbc:mysql://database,database/dbname" p:acquireIncrement="5" p:idleConnectionTestPeriod="300" p:maxPoolSize="100" p:maxStatements="2000" p:minPoolSize="10" p:maxIdleTime="1800" p:maxConnectionAge="3600" p:maxIdleTimeExcessConnections="20" p:numHelperThreads="15" p:preferredTestQuery="SELECT 1"/> and Following are the logs ThreadPoolAsynchronousRunner:743---- com.mchange.v2.async

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

こ雲淡風輕ζ 提交于 2019-12-05 11:12:56
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? Looking at the documentation for NamedParameterJdbcTemplate and JdbcTemplate You have two choices: use NamedParameterJdbcTemplate 's update method. use JdbcTemplate 's update method. There are also some other

JdbcTemplate multiple result sets

荒凉一梦 提交于 2019-12-05 06:53:21
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 have to use the JdbcOperations class which gives me access to more methods, including execute