How to execute Hive hql files from java?

I understand I can do it by parsing the hql file, extracting individual queries and executing each query separately, but I want to know whether there's a better and more graceful way to run a command like:

hive -f "queries.hql"

through java. One way would be using Runtime.getRuntime().exec, but I want to do this the proper jdbc way, using HiveServer2 - if that's possible.

If it's possible, an example would be very much appreciated.

Best Regards.

Relevant tags