com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Today I had a new install of Mandriva 2008 linux. I wrote a java code to test the mysql connectivity. It ended with the following exception.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Last packet sent to the server was 0 ms ago.
Alas, deeper google search gives me a solution that told about the mysql connectivity parameter in /etc/my.cnf
skip-networking
This parameter has been added for some security related reasons. Really I dont know what it is. I just removed that line, which solved this issue.

As I have told you in my previous post, I was trying to read from a table within a loop. I am opening a new connection, new statement and firing the query to get the resultset. It was working fine for a few records, finally it dies with this exception