File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring JDBC - Conversion error

 
Asvin Kumar
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 1107
Eclipse IDE Oracle VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1107
Eclipse IDE Oracle VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
amazing what a good nights sleep will do for you
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic