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...
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 ...
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...
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...
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...
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...
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.
...
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...
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...
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).
...
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...
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...
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...
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) { ...
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...
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...
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 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?
...
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")...
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?
...