Questions tagged [jdbctemplate]

1

votes
3

answer
445

Views

keyHolder.getKey() return null

Why code from 'Spring in action 5' don't work (keyHolder.getKey() return null, but entity is saved in DB)? private long savePizzaInfo(Pizza pizza) { pizza.setCreatedAt(new Date()); PreparedStatementCreator psc = new PreparedStatementCreatorFactory( 'insert into PIZZA (name, createdAt) values (?, ?)'...
lobs
1

votes
0

answer
479

Views

Spring JDBCtemplate ROW Mapper is too slow for a little records

I'm using Spring, postgresql and trying to run a query by JDBCtemplate ROW Mapper. I Have around 1 million records in my db and from the query returned only 12 records. When I'm running this query on the db its taking less than a second but when I'm using JdbcTemplate with a RowMapper its taking aro...
Tal Shani
1

votes
1

answer
98

Views

Select on Northwind database using JPA and JDBC Template

I would like to perform select statement on Northwind database like this bellow. select distinct b.*, a.CategoryName from Categories a inner join Products b on a.CategoryID = b.CategoryID where b.Discontinued = 'N' order by b.ProductName; I have two problems regarding this operation : I have crea...
jocom
1

votes
0

answer
226

Views

jdbctemplate postgres json

Hi, please suggest me what can i do? I'm using postgres and i have 2 fields table: -id(bigint) -attributes(jsonb) attributes structure = { id: '...' , name: '..'} I need to check if there's an object with the same id in json so i have a method: `public Optional getIdByAtlasId(Long atlasId) { Stri...
Kirill Raetsky
1

votes
0

answer
75

Views

Tomcat pool property QuerytimeoutInterceptor set is overridden by querytimeout set in jdbctemplate

Tomcat pool property QuerytimeoutInterceptor set is overridden by querytimeout set in jdbctemplate. Is it normal behaviour ?
Manoj Manohara kumar
1

votes
1

answer
264

Views

How best to handle Constraint Violations in Spring JDBC

What is considered the best/most correct way to handle a Constraint Violation in Spring JDBC? As a real example. I've got a users table that contains, amongst other things, columns of url_slug and email. Both of these are UNIQUE. When creating a new record, or updating an existing record, if I try t...
Graham
1

votes
0

answer
26

Views

Insert parent and (n) children using stored procedure

I am having some difficulty writing the stored procedure to insert a parent record and 'n' number of children records. I am using MySQL with Java and Spring NamedParameterJdbcTemplate. My DB tables are: contact: id firstName lastName .... contact_phone: id contactId number .... You can see the relat...
Gremash
1

votes
1

answer
156

Views

How to custom the type of value in the map returned by jdbcTemplate.queryForMap()?

Suppose I hava a table with a column named status whose type is tinyint(1), and I use the following jdbc query to get a specific row from database, but now the queryForMap() method here will auto convent the tinyint(1) status field to the type boolean, but in fact I'm not only going to use this fiel...
Azarea
1

votes
1

answer
182

Views

How to obtain the generated keys when using the NamedParameterJDBCTemplate in a batchUpdate

I'm trying to understand how to perform a batch insert statement (for speed improvement) and obtain the created primary key values for the newly created records. I have seen the KeyHolder interface, but there seems to be no function that combines it with a batch update only a single update (which I...
LouisS
1

votes
0

answer
445

Views

Spring Boot Database connection Table not found

I am developing my first Spring Boot Application and i am facing a problem with the database connection. I am Using maven 4.0.0 and i want to operate on the Database(H2) using JdbcTemplate. I tried to configure the database access in the application.properties file, which i created in the resources...
hiaslosch17
1

votes
0

answer
32

Views

Tomcat jdbc connection pool - idle connection is not created after abandoned was removed

I've configured to have a least 10 idle connections in my connection pool. Sometimes due to unknown reason I there are some abandoned connections that are stuck. To remove then I added configuredDataSource.getPoolProperties().setRemoveAbandonedTimeout(300); configuredDataSource.getPoolProperties()...
Vitalii
1

votes
1

answer
272

Views

cant overcome this org.springframework.dao.dataaccessexception

I am learning Spring boot and am doing a project with jdbcTemplate performing CRUD operations. Whenever, I introduce the getObject() parameters in my query the exception shows up. The IDE suggests to add exception or to surround with try catch; both of which lead to an error 'Incompatible types Ex...
Raavan
1

votes
0

answer
181

Views

Fetching data from Postgres database in batches

I am using Java to read(SELECT) from Postgres Database using JDBC API. But the problem is ,the number of rows returned from the query is in millions (approx 600 millions) and I can allot a fixed memory size for the application which is why it is giving 'OutOfMemory'. Is there a way to fetch data fro...
ujjwal_kumar
1

votes
0

answer
37

Views

Sybase is loading incorrect numeric data sent by Spring batch - Jdbc Template

I have a ETL job built using spring batch and DAO layer uses Spring's jdbc template.The issue is with loading of numeric datatype. When the batch is running for large number of records, good amount of numeric values(not all) will be loaded incorrectly(pattern is that value will be multiplied by 10^s...
user2156418
1

votes
0

answer
26

Views

Spring security authorization not happenning

My following code snippet of security configuration in spring boot authenticates but does not authorize. Could you help in pointing out the error?? Securityconfig.java package com.vaidiksanatansewa.guruji.security; import javax.sql.DataSource; import com.vaidiksanatansewa.guruji.service.UserloginSer...
Raavan
1

votes
1

answer
126

Views

Spring JDBCTemplate Execute Not Throwing Exceptions

I've got a spring application, one of it's functions is to be able to take any piece of SQL and run it, a poller polls a folder for a trigger file containing the location of a SQL file, the application then reads the SQL file and places contents into the 'sqlquery' message header. Problem we seem to...
Markie
1

votes
1

answer
198

Views

Mockito Test Case for Jdbc template and Spring's keyHolder

I wrote a test case but I get a null pointer exception at the return KeyHolder.getKey() line. My test case looks like this: @InjectMocks private UserDAOImpl userDAO; @Mock private JdbcTemplate jdbcTemplate; @Mock private KeyHolderFactory keyHolderFactory; @Before public void setup() { MockitoAnnotat...
Amit
1

votes
0

answer
84

Views

postgresql get timestamp column as zonedatetime

I want to take a postgresql table record of type TIMESTAMP WITH TIMEZONE using Spring-Boot's JdbcTemplate. I got the below error while fetching timestamp column as Java 8's ZonedDateTime i.e (queryForObject(myQuery, ZonedDateTime.class)) Type mismatch affecting row number 0 and column type 'timesta...
madhusdhnn
1

votes
0

answer
206

Views

SimpleJdbcCall: Reading a CLOB returned from stored procedure

I have DAO function that calls DB procedure using SimpleJdbcCall. However i am unable to read the CLOB data returned from stored procedure. When i try to do a .toString() on the returned CLOB value ( result.get('OUT_RTN_XML') ), I just get this in the string : [email protected] Below is the c...
Nick M
1

votes
0

answer
36

Views

Comparing JDBCTemplate and Hibernate for data access using spring

I have used both jdbcTemplate and Hibernate, but I am having a hard time comparing jdbcTemplate and hibernate in the context of performance, query execution time and batch updates. My View and research did so far. As hibernate uses HQL then its query is first translated into native language query an...
Thinker
1

votes
1

answer
336

Views

How to make streaming sql in spring jdbc template?

We have a sql in spring jdbc template fetching millions of records, which we want to process in Java.. Any way to do the same using less memory?
Vijay Kumar Chauhan
1

votes
1

answer
80

Views

jdbcTemplate and raw JSON column

Suppose I query a table which contains raw json in a column, or create json myself with a subquery like this: select p.name, (select json_build_array(json_build_object('num', a.num, 'city', a.city)) from address a where a.id = p.addr) as addr from person p; How can I instruct Spring's NamedParameter...
yglodt
1

votes
0

answer
33

Views

Merge 2 Resultsets using JDBCTemplate

I'm modifying a stand alone Spring 3.0.6 application that uses JDBCTemplate. The main problem is that I have to extract information from two different Oracle databases for which I created 2 Datasources: Added the 2 datasources in an applicationContext.xml. Created an interface that serves a DAO with...
Pablo Vargas
1

votes
1

answer
182

Views

jdbcTemplate.update freezes

I'm using a Spring JdbcTemplate without a 'transactionManager' since I have mostly select to do. When I try to call select queries from JUnit, it works, but when I try to call an 'update', it freezes the test (no connection timeout, nothing, just waiting). I've seen examples of jdbcTemplates insert/...
Tristan
1

votes
2

answer
58

Views

Retrieve large data over 200 MB from db JdbcTemplate

Is there any better way to retrieve data in chunks instead of whole at a time and paginate them? I'm trying to retrieve large data over +300k rows (200 MB) using JdbcTemplate queryForList and return a paginated response for my API. I couldn't find any feasible column name to sort the data per my nee...
roj
1

votes
0

answer
38

Views

Creating multiple object with one response using Spring FrameWork

This is my first time using Spring to add and get data from a database. I have successfully established connection with my database and can add Plants with only id and plantName but now for the part that I do not understand. How can I create an RowMapper or something else that would work with a loo...
Richard
1

votes
0

answer
114

Views

jdbcTemplate.batchUpdate not inserting rows

I'm trying to do a batch insert, but when run in Tomcat the app seems to hang, and no new rows inserted. Below is my code: public class MatchDAOImpl implements MatchDAO { private JdbcTemplate jdbcTemplate; public MatchDAOImpl(DataSource dataSource) { jdbcTemplate = new JdbcTemplate(dataSource); } @O...
Martyn
1

votes
1

answer
28

Views

JOOQ update set not populating values

In a Spring Boot application, I am using JOOQ to build SQL which is then being executed through JdbcTemplate. I am not using codegen or executing queries with JOOQ. The problem I have run into is with doing an Update. I'm using table() and field() as static imports from org.jooq.impl.DSL. The table...
Johnny Hamerstix
1

votes
1

answer
15

Views

'Parameter index out of range (2 > number of parameters, which is 1).' for a two parameter statement

I'm following this tutorial to learn about Spring JdbcTemplate, and it has the following example which works fine: public void deleteDog(String name, Long id) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); jdbcTemplate.update('DELETE FROM dog WHERE name='' + name + '' AND id=' + id); }...
Lewis Cawthorne
1

votes
0

answer
45

Views

java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist : jdbcTemplate

We are using jdbc template for communicating with oracle database in our project and after deployment it is throwing following exception. org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [select count(*) from users where temp_id = ?]; nested exception is ja...
Pawan Patil
1

votes
1

answer
29

Views

How to get full sql script with replaced wild cards in jdbcTemplate?

I have following code public class Foo{ private final NamedParameterJdbcTemplate nJdbcTemplate; public void bar(....){ String query = 'INSERT INTO .... .... nJdbcTemplate.batchUpdate(query, mapSqlParameterSourcesArray); } } I want to get full , valid insert SQL script to insert it into another datab...
gstackoverflow
1

votes
0

answer
35

Views

Connecting to different Databases for Every HTTP Rest call in Spring MVC

I'm writing rest API to provide access to users to different SQL databases on the same DB server. Example: DB1: jdbc:postgresql://localhost:9090/test1 DB2: jdbc:postgresql://localhost:9090/test1 .....50 Databases. Here is my scenario, Every HTTP request from user has an associated ID. Once the end...
1

votes
2

answer
1.7k

Views

JdbcTemplate batch update in postgresql - date loses time?

I am inserting a list of object with java.util.date in format YYYY-MM-DDThh:mm:ssTZD (2008-09-26T14:34:59+02:00). SQL: INSERT INTO cdate (key,valuedate,user_id) VALUES(?,?,?) BatchPreparedStatementSetter bpss = new MetaJdbc().setMetaBatchPreparedStatement( list, userId); getJdbcTemplate().batchUpdat...
Trick
1

votes
1

answer
10.2k

Views

Spring JdbcTemplate ConnectionPooling Configuration

I am working on a Spring MVC application in which I have recently been convinced to revamp my database code. Before I was using very traditional JDBC code that I have been told was very 'old school' because of the boilerplate code. I have been making the transition to using JdbcTemplate with Spring....
TheJediCowboy
1

votes
1

answer
227

Views

Spring JDBCTemplate on Seam-based app

When manual SQL is required (JDBC API with pre-written queries), what is the best approach in a Seam-based application ? In Seam Documentation, use of Spring bridge to inject a Spring JDBCTemplate is defined as the most complex to setup, but the easiest for development. Do you agree with that ?
Benoît Guérout
1

votes
2

answer
1.9k

Views

Springs SimpleJdbcInsert doesn't produce auto-generated keys as expected

I'm using springs SimpleJdbcInsert to execute an JDBC insert and return 2 auto-generated keys. The command I use is: KeyHolder keys = insert.withTableName('TRANSACTION').usingGeneratedKeyColumns('TRANSACTIONID', 'ROWID').executeAndReturnKeyHolder(params); But keys only contains one key named SCOPE_I...
David Parks
1

votes
1

answer
6.7k

Views

JDBC Template PreparedStatementCallback error HELP?

I was testing to transfer data of the result query to a String variable but when I did I received this bunch of errors, I don't have any idea why did this occured, I tested my query in mysql and it worked, but how come in my code isn't? here's my test code package test; import dao.FinanceDao; import...
user962206
1

votes
1

answer
254

Views

Using unnamed procedural code in JdbcTemplate

I have a table in an Oracle database where three columns are automatically populated by a trigger when a row in inserted. To retrieve those values when the insert happens, I am using some procedural code but it doesn't exist as a named stored procedure. The code looks something like this but with...
spaaarky21
1

votes
1

answer
227

Views

What is the best way to get our Person into our User using spring jdbcTemplate

I have two domain objects: User (which has a Person) Person FYI: In our domain there are Persons (people :-) that are not users so we can't just combine them. I am trying to figure out the best way of getting the Person object populated into the User object. I have come up with 3 possible solutions...
testing123
1

votes
1

answer
1.1k

Views

Trying to access OS400/DB2 Stored Procedure Output Parameters from Java with Spring JdbcTemplate

Trying to access OS400/DB2 Stored Procedure Output Parameters from Java with Spring JdbcTemplate. My Stored Procedure last parameter is a input/out parameter if the record is updated I will get back 'Y' from the main frame. Can someone please give me a close on how to access the 2nd parameter and...
SJS

View additional questions