• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to convert an Object to integer?

 
Ben Koh
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's see your query, and the relevant section of code where this is happening.
 
Marcos Maia
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help guys, I think I've got it. Cheers!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic