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
0 answers

Update, Insert and delete in one spring boot PUT Request jdbcTemplate

In a Put Request the JSON file should be checked for all entries and this should be compared with the database. I have a variable that has the last database entry, e.g. the database has two entries, but there are three entries in the JSON file. In…
0
votes
0 answers

@Transactional annotation does not rollback

I struggle to get @Transactional to work in combination with NamedParameterJdbcTemplate.batchUpdate() in an enterprise application. It was hard to debug, so I built a working minimal example in Spring Boot just to check my approach. In the minimal…
Yanick Nedderhoff
  • 1,174
  • 3
  • 18
  • 35
0
votes
0 answers

How to perform batch update with Map using JdbcTemplate in Spring JDBC?

I have a bean which has two fields 1: Map client 2: String target I have to write this bean to the database. I have a query "INSERT INTO my_table(client_key ,client_value ,target) VALUES(?,?,?)" So every key-value pair and the String…
0
votes
3 answers

Database is not accessing by the project done in Spring Boot

I am new to spring boot and I want to connect my database with jdbc to spring boot project. It is succeeding only for one database and when I change the name of database to another it won't work. In my project I have done only connecting database to…
Kamalka Fernando
  • 153
  • 1
  • 2
  • 13
0
votes
1 answer

Issue using Oracle date function with Spring's NamedParamenterJdbcTemplate

I'm having an issue trying to get my SQL query which works fine in SQL Developer (Oracles free database tool) to also work using Spring's NamedParameterJdbcTemplate class. My query is: String sql = " SELECT COUNT(*) FROM ( " + "…
C0deAttack
  • 24,419
  • 18
  • 73
  • 81
0
votes
0 answers

Getting Error Connection oracle.jdbc.driver.T4CConnection marked as broken because of SQLSTATE(08003),

Application is configured with Hikari library to manage database connections. Recently upgraded ojdbc jar from ojdbc7 to ojdbc8 and spring jdbc version from 4.3.10.RELEASE to 5.2.9.RELEASE then we are seeing this issue. Here are hikari cp…
0
votes
1 answer

Facing problem in mapping the custom result record from postgres function

My Postgres function is in below link postgres function I am trying to store in Object & created separate Entity but does not work for me. my spring JDBC code as follow Session session = em.unwrap(Session.class); …
0
votes
1 answer

Spring JDBC with PostgreSQL native query with list as a parameter not working

I am using PostgreSQL as a Database server. and using SpringJDBC template for fetching below details. My spring code as below List clbkTyps = new ArrayList(); clbkTyps.add("ADD"); clbkTyps.add("UPDATE"); clbkTyps.add("DELETE"); …
0
votes
0 answers

spring data jdbc get the next value sequence from Oracle?

In JPA is simple to get the next value from DB with the @Generated etc. In spring data JDBC working with autogenerated DB IDs is simple/natural. But how about working with PKs/Ids that are not auto generated like in Oracle Sequence?
DanutClapa
  • 592
  • 2
  • 7
  • 23
0
votes
0 answers

mssql jdbc: The column name is not valid

I'm trying to execute this sql query: SELECT TOP 150 'giac_img' AS font, im_notext1.nt1_codi_arxiu AS codi_arxiu, im_notext1.nt1_codi_fons AS codi_fons, im_notext1.nt1_unitat AS codi_unitat, …
Jordi
  • 20,868
  • 39
  • 149
  • 333
0
votes
1 answer

Spring DriverManagerDataSource not found

I have a spring project and i want to create a bean with the DriverManagerDataSource class. I have looked around and found that most people with this issue didn't have spring-jdbc in their pom.xml so I triple checked and I do have the latest version…
dbr
  • 17
  • 6
0
votes
2 answers

ItemPreparedStatementSetter invalid in out parameter

In a spring batch application, I try to do an insert. My query public static final String = "insert into event(event_id, billingid, event_type, event_date, event_status, bill_date, is_mobile_payment, score, reason_id, created_date, created_by)…
robert trudel
  • 5,283
  • 17
  • 72
  • 124
0
votes
1 answer

Kotlin JdbcTemplate Null

I'm trying to convert my application from java to kotlin and am using a mix of Java and Kotlin at the moment. I'm trying to convert my repository classes to Kotlin first. This is using Spring JDBC. Am I doing anything wrong ? package…
grassbl8d
  • 2,089
  • 4
  • 24
  • 34
0
votes
1 answer

The SQL Table is not being created from the schema-mysql.sql file

I am trying to make an application using Spring Boot and JDBC. However, the creation of the Table is not getting initiated. I have created a schema-mysql.sql file to have the table created. The schema-mysql.sql file is as follows: DROP TABLE IF…
Vic
  • 3
  • 2
0
votes
2 answers

How to pass a parameter value into a JDBC repository @Query

I'm trying to use a Lookup strategy of JDBC repository: @Query("select * from USERS where USERNAME = :id") User findById(@Param("id") UserId id); As you can see an id parameter has the custom type UserId. How can I convert it to a simple String?…
pto3
  • 513
  • 1
  • 5
  • 13
1 2 3
99
100