This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes JDBC and the fly likes rs.getInt() on varchar column. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "rs.getInt() on varchar column." Watch "rs.getInt() on varchar column." New topic
Author

rs.getInt() on varchar column.

Akshay Bhatia
Greenhorn

Joined: Sep 24, 2004
Posts: 26
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

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Sep 24, 2004
Posts: 26
SQl VARCHAR type maps to String Java datatype. getInt() returns an primitive int.

Akshay.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Aug 15, 2004
Posts: 2874
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: rs.getInt() on varchar column.
 
Similar Threads
XSLT vs JSP
java.lang.NumberFormatException when sorting table column
how to convert?
prepareStatement returns 0?
db-create-table: [java] SQL Error at line 340: java.sql.SQLException: Table not