spring-jdbc

How to use Spring's JdbcTemplate to connect to a simple MySql database?

谁说胖子不能爱 提交于 2019-12-30 06:06:43
问题 I am trying to use Spring's JdbcTemplate Class to connect to a simple MySql database based on this tutorial. In fact, I used their project setup: pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>test</groupId> <artifactId>jdbc-test</artifactId> <version>0.0.1-SNAPSHOT</version> <parent>

Spring JDBC : unable to get dataSource

十年热恋 提交于 2019-12-24 21:42:37
问题 I have a spring XML config file called appConfig.xml which contains a datasource bean and another JDBCtemplate to which datasource is passed as an argument: <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"></property> <property name="url" value="jdbc:mysql://localhost:3306/test"/> </bean> <bean id="JDBCTemplate" class="com.myprojects.JDBCTemplate"> <property name="dataSource" ref=

DeadlockLoserDataAccessException in Spring Batch

走远了吗. 提交于 2019-12-24 08:47:13
问题 I am struggling trying to find a solution to this and I'm hoping that someone out there can help. We have a Spring/Hibernate/Wicket/Tomcat webapp. We use Spring Batch for executing jobs in the background. Some execute every minute and check a database table in an external system to see if there are new records. So there are several jobs (maybe 8 or so) that are executing on some fixed interval. A couple of those jobs we have to do some manual queries to ensure there isn't a second one running

Insert 1000s of records with relationship and ignore duplicates using JDBC & MySQL

让人想犯罪 __ 提交于 2019-12-24 08:16:36
问题 I am refactoring some code that was horribly inefficient but am still seeing huge load on both my MySQL and Java servers. We have an endpoint that allows a user to upload a CSV file containing contacts with a first name, last name, phone number, and email address. The phone number and email address need to be unique for a location. The phone number however is stored in separate table from a contact as they can have more than one. The CSV only allows one but they can update a contact manually

How can I create a dynamic query for Spring Integration JDBC outbound-channel-adapter?

99封情书 提交于 2019-12-24 01:05:51
问题 I need to create a dynamic update statement to be be executed by a jdbc:outbound-channel-adapter, because I need to set one field using a case expression that has variable number of conditions as follows: UPDATE tableA SET fieldA = CASE WHEN fieldB IN ('a','b') THEN 1 WHEN fieldB IN ('c','d') THEN 2 ... WHEN fieldB IN (...) THEN N END WHERE fieldC = :headers[MY_FIELDC] I can create this dynamic update statement in a Spring expression as follows: "'UPDATE tableA SET fieldA = ' + headers[MY

Named parameter doesn't work with MySql LIKE statement

拈花ヽ惹草 提交于 2019-12-23 12:37:13
问题 I'm trying to organize a search function on the site, using the Spring-jdbc NamedParameterJdbcTemplate. public List<PhoneEntry> searchPhoneEntries(String search, String username) { String SQL = "select * from entries, users where users.enabled=true " + "and entries.username=:username " + "and concat(secondName, firstName, patronymic, mobile, tel, " + "address, entries.email) like ('%:search%')"; MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue("username", username);

how to get errors(if possible), exceptions,fails,success counts and ids from jdbctemplate batchupdate?

北战南征 提交于 2019-12-23 06:06:16
问题 I am using the below code to do the same. Whenever an sql error occurs(eg: number out of range) batch update stops and getting the result(int array) as null. so i added ignore to the update statement. Now the batch is getting completed ignoring the sqlerror. This time I am getting failureids(ids skipped) and successids(ids processed as well as errors and exceptions). But i want the counts/ids of success,failures,errors,exceptions separately. how do I do that? Also i added

how to get errors(if possible), exceptions,fails,success counts and ids from jdbctemplate batchupdate?

我是研究僧i 提交于 2019-12-23 06:04:06
问题 I am using the below code to do the same. Whenever an sql error occurs(eg: number out of range) batch update stops and getting the result(int array) as null. so i added ignore to the update statement. Now the batch is getting completed ignoring the sqlerror. This time I am getting failureids(ids skipped) and successids(ids processed as well as errors and exceptions). But i want the counts/ids of success,failures,errors,exceptions separately. how do I do that? Also i added

Overriding timeout for database connection in properties file

拟墨画扇 提交于 2019-12-23 03:55:08
问题 I was wondering if there is a specific way to override database connection timeout in the properties file in my Java web project? I am using Hibernate, Spring, and MySQL DB. I have tried several different property fields and reduced the timeout time to 1 millsecond, yet the connection is still completed with transactions still being processed properly. These are the property fields I have used to no avail... spring.jpa.properties.javax.persistence.query.timeout=1 spring.jdbc.template.query

Spring JdbcTemplate Insert throws uncategorized SQLException

与世无争的帅哥 提交于 2019-12-23 02:57:23
问题 I am inserting a new row into a table with Spring JDBCTemplate. The jdbcTemplate.update() throws the following exception: PreparedStatementCallback; uncategorized SQLException for SQL []; SQL state [99999]; error code [17090]; operation not allowed But the row is inserted into the db anyway. Here's the code: final StringBuilder widgetInsert = new StringBuilder(); widgetInsert.append("INSERT INTO WIDGET (ID, KEY, DEPT_NUM, TYPE, CREATED_BY_ID, CREATED_DATE) "); widgetInsert.append("VALUES