Hello neha singh tomar,
Welcome to CodeRanch!
Pleae
UseCodeTags so that code will be easier to read.
As you can see, in catch block, the code prints the stack trace. But if you don't put return statement there, code will proceed in the same method.
Now, in the given code, even if IBM DB2 driver is not found, without the return statement, code will follow saying 'driver loaded successfully' and attempting to get the connection, which we don't want.
The return statement simply returns from the method, without executing any further code.
Another approach for the same would be throwing your own exception in such cases.
I hope this helps.
Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)