Question: I am moving from PHP to Java and I'm a little struggled.

I have this method like this that I use to get some data from MySQL database and I would like to treat the failure if no data got from database.

```
public double getRate() {
    double ret;
    try {
        // do a select query
        PreparedStatement stmt = conn.prepareStatement("SELECT `rate` FROM `rates` LIMIT 1");
        ResultSet rs = stmt.executeQuery();

        // get result
        rs.absolute(1);
        ret = rs.getDouble(1);

        // close the resources
        rs.close();
        stmt.close();
    }

    // this catches only the SQL errors (if I am right)
    catch (SQLException ex) {
        ex.printStackTrace();
    }

    // THIS IS WRONG BECAUSE "variable ret might not have been initialized"
    return ret;
}

```

In PHP we can return whatever in case of failure like this:

```
<?php

public function getRate() {
    $ret = db::getOne("SELECT `rate` FROM `rates` LIMIT 1");
    if ($ret) { 
        return $ret; // row has been found, so we return it
    } else {
        return false; // row hasn't been found, so we return false --> THIS is what I need to do in Java
    }
}

?>

```

**So how to treat a failure in Java methods/functions where I have nothing to return?**

Answer: 
You could make your method return an object of the double wrapper class `Double`. Then you could return a null pointer in case of some failure.

```
public Double getRate() {
    ...
    if(ok)
        return new Double(ret);
    else
        return null;
}

```
Initialize your double variable with a control value. If it is not changed when exiting the method, then something went wrong. 

The control value can be something you do not expect to get from the query, so for rates it could be a negative number, say `-1` since rates can't be negative.

```
double ret=-1.00d;

```