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
440
votes
6 answers

Spring - @Transactional - What happens in background?

I want to know what actually happens when you annotate a method with @Transactional? Of course, I know that Spring will wrap that method in a Transaction. But, I have the following doubts: I heard that Spring creates a proxy class? Can someone…
peakit
  • 28,597
  • 27
  • 63
  • 80
127
votes
14 answers

Spring Boot default H2 jdbc connection (and H2 console)

I am simply trying to see the H2 database content for an embedded H2 database which spring-boot creates when I don't specify anything in my application.properties and start with mvn spring:run. I can see hibernate JPA creating the tables but if I…
Aaron Zeckoski
  • 5,016
  • 8
  • 25
  • 48
116
votes
5 answers

Spring DAO vs Spring ORM vs Spring JDBC

I was going through data access technologies supported by Spring, and I noticed that it mentions multiple options and I am not sure about the difference among them: Spring-DAO (http://docs.spring.io/spring/docs/2.0.8/reference/dao.html) Spring-ORM…
Pat
  • 2,223
  • 4
  • 19
  • 25
108
votes
5 answers

JPA vs Spring JdbcTemplate

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…
aem999
  • 16,923
  • 4
  • 22
  • 12
92
votes
7 answers

Spring JDBC Template for calling Stored Procedures

What is the correct way to invoke stored procedures using modern day (circa 2012) Spring JDBC Template? Say, I have a stored procedure that declares both IN and OUT parameters, something like this: mypkg.doSomething( id OUT int, name IN…
adarshr
  • 61,315
  • 23
  • 138
  • 167
86
votes
8 answers

Seeing the underlying SQL in the Spring JdbcTemplate?

I am learning about the wonders of JdbcTemplate and NamedParameterJdbcTemplate. I like what I see, but is there any easy way to see the underlying SQL that it ends up executing? I'd like to see this for debug purposes (in order to for example debug…
Artem
  • 6,420
  • 6
  • 26
  • 26
54
votes
14 answers

Spring Boot: Jdbc javax.net.ssl.SSLException: closing inbound before receiving peer's close_notify

I am currently learning more about implementing JDBC and using databases in a Spring Boot webapp, and I encountered the following Stack Trace written in the bottom of the post. I have created a simple Employee model, and I am trying to execute some…
DP Park
  • 815
  • 1
  • 9
  • 19
48
votes
2 answers

NamedParameterJdbcTemplate vs JdbcTemplate

I'm a beginner to Spring3.x , I'm learning Spring DAO support. I want to know the difference between NamedParameterJdbcTemplate and JdbcTemplate. Which one is the best by means of performance. And when to go for NamedParameterJdbcTemplate and when…
Ashok
  • 587
  • 1
  • 4
  • 5
47
votes
8 answers

Spring Security circular bean dependency

I'm currently working on a Vaadin spring application. According to the app specifications, authentication/authorization of the users must be completed by querying database via jdbcTemplate. How to solve this issue? I'm using Spring Boot…
Malakai
  • 3,011
  • 9
  • 35
  • 49
46
votes
21 answers

HSQL database user lacks privilege or object not found error

I am trying to use hsqldb-2.3.4 to connect from Spring applicastion. I created data base using the following details Type : HSQL Database Engine Standalone Driver: org.hsqldb.jdbcDriver URL: jdbc:hsqldb:file:mydb UserName: SA Password: SA I created…
Raju Boddupalli
  • 1,789
  • 4
  • 21
  • 29
46
votes
4 answers

How to query for a List in JdbcTemplate?

I'm using Spring's JdbcTemplate and running a query like this: SELECT COLNAME FROM TABLEA GROUP BY COLNAME There are no named parameters being passed, however, column name, COLNAME, will be passed by the user. Questions Is there a way to have…
birdy
  • 9,286
  • 24
  • 107
  • 171
44
votes
9 answers

How to set up datasource with Spring for HikariCP?

Hi I'm trying to use HikariCP with Spring for connection pool. I'm using jdbcTempLate and JdbcdaoSupport. This is my spring configuration file for datasource:
Abhinab Kanrar
  • 1,532
  • 2
  • 20
  • 46
37
votes
8 answers

Spring boot fails to load DataSource using PostgreSQL driver

I have successfully developed a prototype using Spring Boot 1.0.2.RELEASE (was 1.0.1.RELEASE until today). I have searched and searched and tried solutions like: Spring Boot jdbc datasource autoconfiguration fails on standalone tomcat Spring Boot /…
mamruoc
  • 847
  • 3
  • 11
  • 21
34
votes
4 answers

Comparing Querydsl, jOOQ, JEQUEL, activejdbc, iciql and other query DSLs

Can someone point me to some resources about the performance comparison among the different Query DSL libraries available for using with Java, like: Querydsl, jOOQ, JEQUEL, activejdbc, iciql and etc... Background: I m using Spring JDBC template, but…
manikanta
  • 8,100
  • 5
  • 59
  • 66
33
votes
8 answers

How to set autocommit to false in spring jdbc template

Currently I'm setting autocommit to false in spring through adding a property to a datasource bean id like below : But i need to add it specifically in a single java method before executing my…
bad programmer
  • 331
  • 1
  • 3
  • 4
1
2 3
99 100