After wasting so much time i got to know that there was mistake in my syntax to connect with DB. I was using colon ":" instead of slash "/".
(1) if you use sid below is the syntax to get connection:
**"jdbc:oracle:thin:@{hostname}:{port}:{SID}"**
(2) if you use service name, below is the syntax to get connection:
"**jdbc:oracle:thin:@//{hostname}:{port}/{servicename}**"