File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases 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 Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "How to convert an Object to integer?" Watch "How to convert an Object to integer?" New topic

How to convert an Object to integer?

Ben Koh

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

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();
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
Ben Koh

Joined: Aug 06, 2001
Posts: 7
Thanks for your help guys, I think I've got it. Cheers!
I agree. Here's the link:
subject: How to convert an Object to integer?
It's not a secret anymore!