spring-jdbc

How to manage database connection pool in spring jpa?

ε祈祈猫儿з 提交于 2019-12-21 03:34:14
问题 I am using spring-boot in my web application and use spring-jpa to read/write from/to my database. It works very well but I want to understand how to manage the database connections. Below is my properties configuration for database: spring.datasource.url=jdbc:mysql://localhost:3306/test?characterEncoding=utf8 spring.datasource.username=user spring.datasource.password=pwd spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.max-active=500 I have set the maximum

How to programmatically use Spring's JdbcTemplate?

倖福魔咒の 提交于 2019-12-21 01:57:11
问题 We use Spring's JdbcTemplate which is configured through Spring config as illustrated below. Is there a way to do this without injecting the data source? I'd like to just create the JdbcTemplate instance programmatically and "initalize" the datasource using TheOracleDS . Our current config: Java class private JdbcTemplate jdbcTemplate; @Resource(name = "myDataSource") public void setDataSource(DataSource dataSource) { this.jdbcTemplate = new JdbcTemplate(dataSource); } Spring config <jee:jndi

simple jdbc wrapper

こ雲淡風輕ζ 提交于 2019-12-18 14:58:26
问题 To implement data access code in our application we need some framework to wrap around jdbc (ORM is not our choice, because of scalability). The coolest framework I used to work with is Spring-Jdbc. However, the policy of my company is to avoid external dependencies, especially spring, J2EE, etc. So we are thinking about writing own handy-made jdbc framework, with functionality similar Spring-jdbc: row mapping, error handling, supporting features of java5, but without transaction support.

How to use a list of string in NamedParameterJDBCTemplate to get results

◇◆丶佛笑我妖孽 提交于 2019-12-18 14:05:14
问题 Experimenting with Spring-JDBC. I am using this as reference. I am trying to get a list of actors who have the same last name. Running this code gave me the desired results: public List<String> getActorsWithSameLastName(String lastName, NamedParameterJdbcTemplate template) { String query = "SELECT FIRSTNAME FROM ACTORS WHERE LASTNAME=:LASTNAME"; Map<String, String> paramMap = new HashMap<String, String>(); paramMap.put("LASTNAME", lastName); return template.queryForList(query, paramMap,

How exactly work the Spring RowMapper interface?

核能气质少年 提交于 2019-12-18 13:23:35
问题 I am studying for the Spring Core certification and I have some doubts about how Spring handle the JDBC queries: So I know that I can obtain data from my DB tables in various ways depending on the type of data that I expect to obtain: 1) Query for simple type (as an int, a long or a String): I use the queryForObject() method of the jdbcTemplate class, something like it: String sql = "SELECT count(*) FROM T_REWARD"; int rowsNumber = jdbcTemplate.queryForObject(sql, Integer.class); So to obtain

JPA vs Spring JdbcTemplate

纵饮孤独 提交于 2019-12-18 09:55:10
问题 For a new project is JPA always the recommended tool for handling relational data or are there scenarios where Spring JdbcTemplate is a better choice? Some factors to consider in your response: new database schema vs pre-existing schema and tables level of developer expertise ease with which can integrate with a data caching layer performance any other relevant factors to consider? 回答1: Use Spring JdbcTemplate if you don't want to access your database schema via a domain model. Using

Spring JDBC Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver]

大憨熊 提交于 2019-12-18 07:41:28
问题 I wonder if any one could help me with this. I encountered an issue when I tried writing code with Spring JDBC. When I ran the server, I got the message like I mentioned in the title. I have google it and someone said that you should import ojdbc.jar. However, I have already imported it. Here comes my code: <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www

Spring JdbcTemplate and Threading

こ雲淡風輕ζ 提交于 2019-12-18 05:15:15
问题 Is it safe to fork off a Thread to execute an insert using a JdbcTemplate in Swing. It's a logging event and as much as possible I don't want it to affect perceived performance. 回答1: This answer from the Spring forum says yes.t=25965 JdbcTemplate is a singleton that won't change state once it's set. 回答2: Also note that its thread-safety is very well explained in the Spring 3.1 reference documentation: 13.2.1.2 JdbcTemplate best practices Instances of the JdbcTemplate class are threadsafe once

Spring's Stored Procedure - results coming back from procedure always empty

。_饼干妹妹 提交于 2019-12-17 23:32:46
问题 I am using Spring's JdbcTemplate and StoredProcedure classes. I am having trouble getting the stored procedure class to work for me. I have a stored procedure on an oracle database. Its signature is CREATE OR REPLACE PROCEDURE PRC_GET_USERS_BY_SECTION (user_cursor OUT Pkg_Types.cursor_type , section_option_in IN Varchar2 , section_in IN Varchar2) AS .... where TYPE cursor_type IS REF CURSOR; I have create the following stored procedure class to get information from the oracle procedure

Change Spring framework log level in simple example project?

﹥>﹥吖頭↗ 提交于 2019-12-17 19:07:05
问题 When following this Spring example I was expecting to see output like this: Creating tables Inserting customer record for John Woo Inserting customer record for Jeff Dean ... Instead, I got some DEBUG log messages interspersed between every line: Creating tables 12:31:16.474 [main] DEBUG o.s.jdbc.core.JdbcTemplate - Executing SQL statement [drop table customers if exists] 12:31:16.484 [main] DEBUG o.s.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource 12:31:16.484