Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

rs.getInt() on varchar column.

 
Akshay Bhatia
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have posted this because something surprising for me came up during some r n d.


If column's data type is varchar , values are mix of characters and numeric for example..
11111, 11122,aaaa, bbbb etc.

fetching values using rs.getInt(columnname) is throwing exception after character data comes. It is able to fetch numeric values.

It should have thrown exception at the first step.

Why it is not throwing exception at the first step itself




Regards,
Akshay.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why it should have thrown exception at the first step?? i mean have you read it somewhere??

may be it accepts the data and then try to type cast implicitly. when failed to do so then throws an exception.
 
Akshay Bhatia
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SQl VARCHAR type maps to String Java datatype. getInt() returns an primitive int.

Akshay.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Akshay Bhatia:
SQl VARCHAR type maps to String Java datatype. getInt() returns an primitive int.


thanks Akshay, but i know this. what i said is something different. do you know the method rs.getInt()? i mean what is the functionality inside.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java docs says,

"Retrieves the value of the designated column in the current row of this ResultSet object as an int in the Java programming language."

what i would like to mention is, may be this typecasts a string to int when string is found. if gets success then it is ok otherwise throws exception.

how it sounds??

anyways, what was the actual exception. please print the whole message. thanx.
[ October 05, 2004: Message edited by: adeel ansari ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic