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 rs.getInt() on varchar column. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply 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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: rs.getInt() on varchar column.
 
Similar Threads
db-create-table: [java] SQL Error at line 340: java.sql.SQLException: Table not
how to convert?
java.lang.NumberFormatException when sorting table column
prepareStatement returns 0?
XSLT vs JSP