简体   繁体   中英

can't figure out missing return statement error

I am actually trying to fit something like the following in my code which can be found in the link mentioned below the code:

Statement stmt;
ResultSet rs;
boolean done = false;
int i = 0;
while(!done) {
    try {
        stmt = connections[i].createStatement();
        rs = stmt.executeQuery("select * from aTable");
        rs.beforeFirst();
        while(rs.next()) {
            // Do whatever you need with the result set
        }
        done = true;
    } catch(SQLException e) {
        // Catch the exception and try with the next connection
        i++;
    }
}

Link : https://ideone.com/as1XI8

So, I have added int i & boolean done variables on Line #83 & 84 Added while loop starting from line 91 and setting done = true in line 380

Finally, I am incrementing the variable i(i++) on line 389 and closing the while loop on line 463 with the brace.

After doing this, I am getting an error on line 80 ( starting brace just before int iterations = 0; ) in Netbeans saying that "missing return statement".

I already have a return statement on line #460 and can't figure out why I am getting this error.

Could anyone please download the code in your Netbeans/Eclipse and let me know what is wrong?

Thanks !!

As your code format is far from practical, after the return statement in line 460, you have three closing brackets - one for the class, one for the method and one for the while loop, I assume - ensure, that there is a return statement at the end of the method every time, in your case, just move the return statement to the end of the method.

Also, please learn how to format your code, this error has clearly been avoidable by correct formatting and indentation.

You need to return after the while loop is done ! You are return inside the while loop !

Just take your return statement after one of the braces and see the magic

NOTE Please avoid putting down the whole code (escp. this type of messy code), it becomes a pain to go through it ! Take some time to format and make it human readable !

Anyone can write codes that machine can read, its important to write codes that humans can read !

Your return statement is at wrong position. It is in the while loop. write your return statement at line number 462

You need return statement for case when done is true and while loop won't even start. Just add one more return with null or new ResultSet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM