spring-jdbc

simple jdbc wrapper

To implement data access code in our application we need some framework to wrap around jdbc (ORM is not our choice, because of scalability). The coolest framework I used to work with is Spring-Jdbc. However, the policy of my company is to avoid external dependencies, especially spring, J2EE, etc. So we are thinking about writing own han...

How to do simple Spring JDBC transactions outside the IoC container?

The project I'm working on uses straight JDBC data access in all its boilerplate glory and doesn't use any transactions. I feel like using transactions and simplifying the way data access methods are written is important, especially with some changes being made currently. The project has been around for quite a while and isn't suited to ...

Large ResultSet on postgresql query

I'm running a query against a table in a postgresql database. The database is on a remote machine. The table has around 30 sub-tables using postgresql partitioning capability. The query will return a large result set, something around 1.8 million rows. In my code I use spring jdbc support, method JdbcTemplate.query, but my RowCallbackH...

SimpleJdbcTemplate and null parameters

I'm using SimpleJdbcTemplate and MapSqlParameterSource in the folowing way: MapSqlParameterSource parameterSource = new MapSqlParameterSource(); parameterSource.addValue("typeId", typeId, Types.BIGINT); List<Long> ids = _jdbcTemplate.query(_selectIdByParameters, new EntityIdRowMapper(), parameterSource); When typeId ( which is a Long...

Reading a BLOB using JDBC Spring without a result set

I have an Oracle stored procedure that returns a BLOB in an output parameter: PROCEDURE GET_IMAGE_DATA(i_image_type IN NUMBER, o_image_data OUT BLOB) IS BEGIN SELECT IMAGE_DATA INTO o_image_data FROM IMAGES WHERE IMAGE_TYPE = i_image_type; END GET_IMAGE_DATA; I want to use JDBC Spring to read this...

How to programatically use Spring's JdbcTemplate?

We use Spring's JdbcTemplate which is configured through Spring config as illustrated below. Is there a way to do this without injecting the data source? I'd like to just create the JdbcTemplate instance programatically and "initalize" the datasource using TheOracleDS. Our current config: Java class private JdbcTemplate jdbcTemplat...

Get list of all table names from spring SimpleJdbcTemplate

Is there a way to obtain the list of all table names in the database using Spring's SimpleJdbcTemplate? The database being queried is Oracle if that helps in any way. Thanks. ...

Spring JDBC RowMapper with Class Hiearchies

I wanted to know what the community considers the "best practices" in respect to mapping class hierarchies with Spring JDBC. We do not have the ability to use a full fledged ORM tool, however we are using the Spring JDBC to alleviate some of the tedious nature of JDBC. One class which we leverage very regularly are the BeanPropertyRo...

How to call stored procedure to read return value and out parameter both in Spring?

I have a stored procedure which returns an Integer as well as an Out Parameter which is of type VARCHAR. I am using Spring 2.5.6 and unable to find a way to read the return value as well as Out Parameter at the same time. SimpleJdbcCall.executeFunction(..) have a facility to read the stored procedure return value but no facility for Ou...

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 the resulting SQL in an outside tool). ...

can not use resultSet.setFetchDirection(ResultSet.TYPE_SCROLL_SENSITIVE) with spring jdbc DaoSupport with Oracle.

I want to use scrollable resultset, so when I use two lines of code: rs.setFetchDirection(ResultSet.TYPE_SCROLL_SENSITIVE); rs.absolute(12); in my DAOimpl, I get exception, plz help to solve them, thank in advance. import oracle.jdbc.OracleTypes; import org.springframework.jdbc.core.CallableStatementCallback; import org.spr...

Spring Jdbc query execution

Does anyone know how what Spring Jdbc template method I could use to execute this 'upsert' or an alternative approach that would also perform the operations in one database call? UPDATE jasper_report SET Uri = 'update' WHERE ReportId = 99; IF @@ROWCOUNT = 0 AND Exists(Select 1 FROM report Where Id = 99) BEGIN INSERT INTO jasper_r...

using Spring JdbcTemplate for multiple database operations

I like the apparent simplicity of JdbcTemplate but am a little confused as to how it works. It appears that each operation (query() or update()) fetches a connection from a datasource and closes it. Beautiful, but how do you perform multiple SQL queries within the same connection? I might want to perform multiple operations in sequen...

Spring JdbcTemplate - Insert blob and return generated key

From the Spring JDBC documentation, I know how to insert a blob using JdbcTemplate final File blobIn = new File("spring2004.jpg"); final InputStream blobIs = new FileInputStream(blobIn); jdbcTemplate.execute( "INSERT INTO lob_table (id, a_blob) VALUES (?, ?)", new AbstractLobCreatingPreparedStatementCallback(lobhandler) { ...

How to use SQLErrorCodeSQLExceptionTranslator and DAO class with @Repository in Spring?

I'm using Spring 3.0.2 and I have a class called MovieDAO that uses JDBC to handle the db. I have set the @Repository annotations and I want to convert the SQLException to the Spring's DataAccessException I have the following example: @Repository public class JDBCCommentDAO implements CommentDAO { static JDBCCommentDAO i...

Using Spring's KeyHolder with programmatically-generated primary keys

Hello, I am using Spring's NamedParameterJdbcTemplate to perform an insert into a table. The table uses a NEXTVAL on a sequence to obtain the primary key. I then want this generated ID to be passed back to me. I am using Spring's KeyHolder implementation like this: KeyHolder key = new GeneratedKeyHolder(); jdbcTemplate.update(Constan...

UndeclaredThrowableException due to SQLException in Spring + iBatis?

Hello, I am getting the following exception when I typo the SQL driver name or the database server is offline, basically any SQLException. I can't determine where the UndeclaredThrowableException is coming from. Line 194 in SqlMapClientTemplate is this: logger.debug("Obtained JDBC Connection [" + springCon + "] for iBATIS operation...

What does SimpleJDBCTemplate.queryForInt do when the database returns null?

What does SimpleJDBCTemplate.queryForInt do when the SQL query's actual result is null? In particular, what happens if I run queryForInt("select max(foo) from f") and f has no rows? While I'm on this subject, what happens if I run queryForInt("select foo from f") and f has no rows? ...

Spring JDBC stored procedure call with SQLXML parameter

I am using spring 3.0 and MSSQL database, and am having a problem calling a stored procedure using SimpleJdbcCall. The stored procedure requires a parameter of type 'XML'. I've tried this: public void setDataSource(DataSource dataSource) { this.updateDataProc = new SimpleJdbcCall(dataSource). withProcedureName("spUpdateProc")...

Spring jdbc vs iBatis

For Spring 2.5.6 and above the two reasons that I can think of for choosing spring jdbc are : BeanPropertySqlParameterSource - for insert/update ParameterizedBeanPropertyRowMapper - for select These two give you the power of basic orm as you don't need to code your rowmappers. Thoughts/Comments? ...