Thanks! I was using the jars from wrong hive version.
Summarizing, these are the steps I did to resolve this issue:
1. Added a port-forwarding rule to 10000 port of the guest. (This is not present in the default settings of Hortonworks sandbox vm)
2. Downloaded Hive jars (of version, which is specified in the Hortonworks sandbox home page)
3. Added the above jars in classpath and ran the code specified in this forum question.