Well can't really tell you the most efficient way unless you tell me what exactly it's used for.
This code will work, but it can simply use the WHERE command in some situations and it'll be enough, again it all depends on the usage
Code:
int javaKey = 1;
PreparedStatement statement = connection.prepareStatement("SELECT * FROM table_name WHERE some_field='something'");
ResultSet result = statement.executeQuery();
if (result.hasNext()) { //if you're looking for more than 1 result or multiple elements in the table that should return, then you will have to loop until result doesn't have a next
//this means some of the table content has returned from our "statement"
int key = result.getInt("keyName"); //would suggest using the int parameter instead of the string as it's quicker, but this is just to be more user-friendly
if (key == javaKey) {
//do something
}
}