Questions tagged [spring-jdbc]

Spring JDBC is a part of Data access layer provided by Spring. The Spring Framework takes care of all the low-level details that can make JDBC such a tedious API to develop with such as database connections, creating prepare statements, process exceptions etc.,

Spring JDBC is a part of Data access layer provided by Spring. The Spring Framework takes care of all the low-level details that can make such a tedious API to develop with such as database connections, creating prepare statements, process exceptions etc.,

The following are the approaches to form the basis of JDBC database access.

JdbcTemplate is the classic Spring JDBC approach and the most popular. This "lowest level" approach and all others use a JdbcTemplate under the covers, and all are updated with Java 5 support such as generics and varargs.

NamedParameterJdbcTemplate wraps a JdbcTemplate to provide named parameters instead of the traditional JDBC ? placeholders. This approach provides better documentation and ease of use when you have multiple parameters for an SQL statement.

SimpleJdbcTemplate combines the most frequently used operations of JdbcTemplate and NamedParameterJdbcTemplate.

SimpleJdbcInsert and SimpleJdbcCall optimize database metadata to limit the amount of necessary configuration. This approach simplifies coding so that you only need to provide the name of the table or procedure and provide a map of parameters matching the column names. This only works if the database provides adequate metadata. If the database doesn't provide this metadata, you will have to provide explicit configuration of the parameters.

RDBMS Objects including MappingSqlQuery, SqlUpdate and StoredProcedure requires you to create reusable and thread-safe objects during initialization of your data access layer. This approach is modeled after JDO Query wherein you define your query string, declare parameters, and compile the query. Once you do that, execute methods can be called multiple times with various parameter values passed in.

2410 questions
0
votes
1 answer

How to execute batch delete from multiple tables with batch size in spring boot jdbc

I want to delete from 6 tables and they have millions of records.. So I want to delete in batches. currently I use jdbcTemplate.batchUpdate(deleteQueryArray) This may result in deadlock sometimes so I want to delete in batches of size x which will…
Saawan
  • 363
  • 6
  • 24
0
votes
2 answers

Spring Batch Transaction Management - Multi Threaded Step

I am using multi-threaded step in my Batch Job to process records from source DB and write to the destination database. The Step is chunk based and consists of JdbcpagingItemReader, Processor & JdbcBathItemWriter. I understand that if any exception…
LBPS
  • 83
  • 9
0
votes
1 answer

Spring-data JdbcTemplate does not commit

I need to update thousands of records in the database but i would like to commit after a batch of 5000 records. @Service @Transactional (rollbackFor=Throwable.class) public class AttributeProcessorServiceImpl extends DataLoader implements …
Sannu
  • 1,202
  • 4
  • 21
  • 32
0
votes
1 answer

Spring Batch Metadata Connection Debugging

We are periodically getting an error in our application when Spring Batch is attempting to get a connection to the metadata tables. It seems that we have a leak somewhere or somehow that is not releasing or closing connections. What I am looking for…
cneff
  • 388
  • 6
  • 15
0
votes
1 answer

Spring data JDBC migrate to 2.1 - IdGeneration no such method

I'm trying to migrate from 1.1.3 to org.springframework.data:spring-data-jdbc:2.1.0 to get PagingAndSorting. Other dependencies which required updating in order to run my project was: ... id("org.springframework.boot") version…
IOOI
  • 23
  • 7
0
votes
0 answers

How can I use same db session for two procedures in Spring boot

I am developing spring boot application with Oracle database and Hikari cp. In my project I am connecting to db with SimpleJdbcCall. In database, I have a package and I am calling procedures from Java. Some procedures use global variables from…
Semih Koyu
  • 75
  • 6
0
votes
1 answer

Using aggregation with Spring JDBC

I am learning Spring JDBC inserting to database but I could not insert my 2 aggregated classes together. (Employee which has Address class). How can I add Address class' variables to Employee table? Code below, thanks. Employee.java package…
bjorke07
  • 94
  • 1
  • 10
0
votes
0 answers

Insert data to 27 columns in a DB table using SQLParameterSource- failing with ArrayIndexOutOfBounds exception

I am having similar issue while inserting data to a DB table with 27 columns. I am using NamedParameterJdbcTemplate class to insert data. Any help in this regard is really helpful. Please find the below code snippet SqlParameterSource parameters =…
0
votes
1 answer

How to get the value of any column of a row inserted with JdbcTemplate

Can I use Spring's JdbcTemplate to get a column value of a row just inserted? E.g. the SQL looks so: insert into table1 (name, age) values ('name', 20) returning name; And I want to get the value of the name column. The update() method returns the…
ka3ak
  • 2,435
  • 2
  • 30
  • 57
0
votes
1 answer

Why is @ConfigurationProperties needed in building a DataSource in Spring?

If @ConfigurationProperties binds the properties into an object, what is the usage of @ConfigurationProperties in building a…
Jiji
  • 1,092
  • 3
  • 15
  • 36
0
votes
0 answers

Why am I getting a org.springframework.jdbc.UncategorizedSQLException even though the table connects successfully in the project?

I've done JUnit Tests for all my sql statements and it worked correctly but now I am trying to list out the data from my table in an html table and I am getting an HTTP Status 500 – Internal Server Error. Also When I do a main method in my…
0
votes
0 answers

JDBC pagination in one to many relation and mapping to pojo?

we have a messaging logs table and we are using this table to provide a search UI which lets to search messages by id or status or auditor or date. Table audit looks like below +-----------+----------+---------+---------------------+ | messageId |…
krrish0690
  • 51
  • 2
  • 11
0
votes
1 answer

JDBC fetch size resets to 1 for streaming types from oracle documentation

From Oracle JDBC documentation (https://docs.oracle.com/cd/E11882_01/java.112/e16548/oraperf.htm#JJDBC28782) If a column of a result set is of data type LONG, LONG RAW or LOBs returned through the data interface, that is, the streaming types, then…
mallikarjun
  • 1,862
  • 5
  • 23
  • 47
0
votes
1 answer

Get columns from a query with jdbcTemplate BeanPropertyRowMapper

I have a problem and I need help. The problem is that I am trying to get the result of a query using jdbctemplate and map that result in my File class. MY CLASS FILE CONTAINS 3O PROPERTIES: 10 PROPERTIES OF TYPE LONG, STRING AND DATE. @Table (name =…
Kenny Cruz
  • 47
  • 1
  • 8
0
votes
1 answer

spring setter injection call confusion

Below is the code snippet from Spring Reference documentation on Spring-JDBC https://docs.spring.io/spring-framework/docs/3.0.x/spring-framework-reference/html/jdbc.html public class JdbcDao { private JdbcTemplate jdbcTemplate; public…
tin_tin
  • 478
  • 3
  • 10
  • 24
1 2 3
99
100