"Connection refused" usually means there is no server running at the port you tried to connect to.
In your example, that's port 1521 on localhost. Are you running an Oracle server on the same computer where that code was running? And is it configured to listen at port 1521?