File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Spring JDBC - Conversion error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Spring JDBC - Conversion error" Watch "Spring JDBC - Conversion error" New topic
Author

Spring JDBC - Conversion error

Asvin Kumar
Greenhorn

Joined: Mar 01, 2010
Posts: 13


Hi,

I am getting an error while trying to fetch a NUMBER value from a table. The error is,

PreparedStatementCallback; uncategorized SQLException for SQL [SELECT ? FROM MQT_SYNC_TSDISCOUNT WHERE REGION=? AND COUNTRY=? AND TS_OFFER=? and rownum=1]; SQL state [null]; error code [17059]; Fail to convert to internal representation

I know this error would occur when I am trying to do wrong type cast. But this is what my code does to fetch the value,

Integer techGroup = 0;
try
{
techGroup = (Integer)jdbcTemplate.queryForObject(FETCH_DISCOUNT_YEARS, new Object[] { column, region, country, tsOffer }, Integer.class);
}

where the FETCH_DISCOUNT_YEARS = SELECT ? FROM MQT_SYNC_TSDISCOUNT WHERE REGION=? AND COUNTRY=? AND TS_OFFER=? and rownum=1.

Please note that I am using wrapper Integer, i have also tried this way


int techGroup = 0;
try
{
techGroup = jdbcTemplate.queryForInt(FETCH_DISCOUNT_YEARS, new Object[] { column, region, country, tsOffer });
}

and I got the Invalid Column type error. Not sure if there is an issue with fetching SQL NUMBER as Java int.

Please help.

Thanks,
Asvin
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

I have never seen a ? in the columns list before. is this clever spring stuff?

could you show us more code please, at the bit where you set the bind variables I am betting if the first ? is valid it is a variable length argument list, so needs some special handling
Asvin Kumar
Greenhorn

Joined: Mar 01, 2010
Posts: 13
Wendy,

Yes, thats what the problem is. I figured it out in the morning, the fetching column can't be passed, it has to be appended in the SQL string.


Thanks,
Asvin
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

amazing what a good nights sleep will do for you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring JDBC - Conversion error