FAQ Database Discussion Community


Spring JdbcTemplate Insert throws uncategorized SQLException

java,spring,spring-jdbc,jdbctemplate
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...

Can't access the database values using JdbcTemplate

java,oracle,spring-jdbc,jdbctemplate
I'm trying to insert value into Oracle DB using JdbcTemplate, but its throwing the following exception: Can't access the database values using JdbcTemplate. This is how I am trying to insert the values to the DB: package com.sample.common.Dao; import org.springframework.jdbc.core.support.JdbcDaoSupport; public class UserDao extends JdbcDaoSupport { public void insert(){ System.out.println("Tring...

How is the RowMapper Method working from Spring 1.2?

java,spring,jdbc,spring-data,spring-jdbc
I am doing a documentation of a Spring 1.2 implemented giant application for my company which wasn't documented while being coded around 8 years ago. Right now I am on one of the java classes and stuck on a particular method on how it is actually working, specially the part...

Update using Spring+Hibernate

spring,hibernate,spring-jdbc
I want to perform a transaction using Hibernate+Spring.I want to retrieve the data from DB and update the parameter and then persist the same.I am new to hibernate can someone evaluate the code and suggest me the best approach to implement the same.Here is the code snippet: @Repository public class...

Spring MVC @ControllerAdvice exception behavior different based on Exception source

java,spring,spring-mvc,spring-jdbc
Depending on whether a DuplicateKeyException (DKE) is thrown by the call to the NamedParameterJdbcTemplate (i.e. jdbcTemplate.update(sql, namedParameter)) or explicitly thrown by me in the code, the behavior is very different. When the DKE is thrown by the jdbcTemplate call, the correct behavior happens. My @ControllerAdvice kicks in and the correct...

Spring Batch Execution Status Backed by Database

spring-batch,spring-jdbc
From the Spring Guides: For starters, the @EnableBatchProcessing annotation adds many critical beans that support jobs and saves you a lot of leg work. This example uses a memory-based database (provided by @EnableBatchProcessing), meaning that when it’s done, the data is gone. How can I make the execution state backed...

How do I use JdbcPagingItemReader in Spring Batch when my primary key is a string?

java,spring-batch,spring-jdbc
I've got some SQL data that I need to access with an ItemReader in Spring Batch. I thought that JdbcPagingItemReader / PagingQueryProvider would be the perfect fit. The table I'm selecting from has a primary key that is a composite of three columns: INTEGER, VARCHAR, and VARCHAR. And actually, for...

Mysql on duplicate key update with primary key and unique key

mysql,spring-jdbc
I have a table with an auto incremented primary key and also a unique key: CREATE TABLE `product` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `canonical_url` varchar(750) CHARACTER SET latin1 NOT NULL, ... PRIMARY KEY (`id`), UNIQUE KEY `canonical_url_idx` (`canonical_url`) Im using the on duplicate key feature to update records if...

NullPointerException in JdbcTemplate.update()

postgresql,maven,spring-jdbc
I am new to spring and trying spring jdbc with PostgeSQL and getting NullPointerException in DAO class at JdbcTemplate.update(). content is as follows: pom.xml <!-- Spring JDBC Support --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>4.0.2.RELEASE</version> </dependency> <!-- postgreSQL Driver --> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId>...

stored-proc-outbound-gateway fetch size and batch update

spring-integration,c3p0,spring-jdbc
I have been using stored-proc-outbound-gateway for both update and select as the database layer only allows stored procedures to my application. I would like to set jdbc fetch size to a higher number as currently it is taking very long to read records, but i don’t see a way to...

Spring jdbcTemplate: generic code to run a select query with model name provided

java,spring,generics,spring-jdbc
Below is the working code that assumes MyModel class is the model class. void runSql(String sql) { List<MyModel> models = JdbcTemplate.query(sql, params, new BeanPropertyRowMapper(MyModel.class)); for (MyModel model : models) { ... } } How to write generic version of above method that will take model name such as "MyModel" as...

Why aren't BeforeTransaction and AfterTransaction methods firing?

java,spring,junit,spring-jdbc
I have some unit tests that use JUnit and Spring to test a simple DAO. My understanding is that when I mark a class as @Transactional, the @BeforeTransaction and @AfterTransaction methods should run before and after my @Test methods. However, these methods are not being fired at all. I don't...

Using one DataSource object for multiple DB connections - using only one connection at a time

spring,spring-jdbc,spring-4
Can we define only one DataSource object and wire it dynamically at runtime connecting to different databases ? I need to connect to only one database at a time. I will be passing the name of the Database as argument. I will lookup the DB URL and other details from...

Creating multiple databases or schemas with Spring JDBC

mysql,spring,dao,spring-jdbc
i'm currently working on a Spring MVC project where i need multiple databases, one for each person that signs up(i know it's gonna be heavy but the number is limited). So after a person logs in, he should have access only to his database, but how do i do that...

Getting java.sql.SQLException: ORA-02291 for a nullable foreign key

java,oracle,spring-jdbc
I am getting a java.sql.SQLException: ORA-02291 when I try to insert a NULL value to a column which has a foreign key constraint to another table. By definition this column is NULLABLE in the child table and the column it is referencing in the parent is the PK of that...

Spring Batch Repository: JdbcJobInstanceDao

spring,spring-batch,spring-jdbc
I have gone through the grepcode for JdbcJobInstanceDao and find out this code snippet which I am trying hard to understand. According to the Spring Batch Repository Schema, CREATE TABLE BATCH_JOB_INSTANCE ( JOB_INSTANCE_ID BIGINT NOT NULL PRIMARY KEY , VERSION BIGINT , JOB_NAME VARCHAR(100) NOT NULL, JOB_KEY VARCHAR(32) NOT NULL,...

Error of Failed to execute goal org.codehaus.mojo , while doing SpringJDBC example

spring,maven,spring-jdbc
I am doing Springjdbc example from the site http://www.journaldev.com/2593/spring-jdbc-and-jdbctemplate-crud-with-datasource-example-tutorial. After ececuting i am getting error of --- exec-maven-plugin:1.2.1:exec (default-cli) @ SpringJDBCExample --- Feb 16, 2015 10:43:41 AM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh INFO: Refreshing org[email protected]5d099f62: startup date [Mon Feb 16 10:43:41 IST 2015]; root of context hierarchy Feb 16, 2015 10:43:41 AM...

Spring store data in jdbcTemlate(h2 db) permanently

spring-data,spring-jdbc,jdbctemplate
I am starting to learn Spring and faced with some issues regarding spring-jdbc. First, I tried run the example from this: https://spring.io/guides/gs/relational-data-access/ and it worked. Then, I commented lines with droping and creating new tables(http://pastebin.com/zcJHsL1P), in order to not override data, but just get it from db and show it....

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

java,mysql,maven,spring-boot,spring-jdbc
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>...

Mixing JdbcTemplate and raw JDBC

spring,spring-boot,spring-data,spring-jdbc
I am experiencing some strange behaviour which I can't easily explain. The following code runs fine: try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { statement.executeUpdate("DELETE FROM product"); } catch (Exception ex) { throw new RuntimeException(ex); } try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { statement.executeUpdate("INSERT INTO...