my dog learned polymorphism*
The moose likes JDBC and the fly likes How to convert an Object to integer? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to convert an Object to integer?" Watch "How to convert an Object to integer?" New topic
Author

How to convert an Object to integer?

Ben Koh
Greenhorn

Joined: Aug 06, 2001
Posts: 7
Dear gurus, I am having trouble in converting an object to an integer. The object actually is an item from a Jcombobox and i need to compare it against a field that has been declared as a number in the database. I received the following error:
"java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression."
I have tried casting it to an integer but to no avail. Any help would be really appreciated. Thanks!
Nathanael Ulrick
Greenhorn

Joined: Jul 17, 2001
Posts: 22
Let's see your query, and the relevant section of code where this is happening.
Marcos Maia
Ranch Hand

Joined: Jan 06, 2001
Posts: 977
As long as you did not post any code I�m gonna make somme assumptions:
lets supose you have a String object and you�re sure that it has an integer value you coul�d use ex(suppose you�ve recover the String value from your combo):
String s = "244";
Integer integer = new Integer(s);
int i = integer.intValue();
regards.
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

String s = "244";
int i = Integer.parseInt(s); //if it is an integer value
Double d = Double.parseDouble(s); //if it needs precision
Long....etc.//for large integer values
Jamie
Ben Koh
Greenhorn

Joined: Aug 06, 2001
Posts: 7
Thanks for your help guys, I think I've got it. Cheers!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to convert an Object to integer?
 
Similar Threads
How to add COM wrapper to Java object?
wrapper classes
getObject returning 'null' on SQL Server nvarchar type
Problem with Database and Vectors
Printing an Object without casting!