title: How to set configuration in Hive-Site.xml file for hive metastore connection?
body: <p>I want to connect MetaStore using the java code. I have no idea how to set configuration setting in Hive-Site.xml file and where I'll post the Hive-Site.xml file. Please help.</p>
  
  <pre><code>import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.ResultSet;
  import java.sql.Statement;
  
  import org.apache.hadoop.fs.Path;
  import org.apache.hadoop.hive.conf.HiveConf;
  import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
  
  public class HiveMetastoreJDBCTest {
  
      public static void main(String[] args) throws Exception {
  
          Connection conn = null;
          try {
              HiveConf conf = new HiveConf();
              conf.addResource(new Path("file:///path/to/hive-site.xml"));
              Class.forName(conf.getVar(ConfVars.METASTORE_CONNECTION_DRIVER));
              conn = DriverManager.getConnection(
                      conf.getVar(ConfVars.METASTORECONNECTURLKEY),
                      conf.getVar(ConfVars.METASTORE_CONNECTION_USER_NAME),
                      conf.getVar(ConfVars.METASTOREPWD));
  
              Statement st = conn.createStatement();
              ResultSet rs = st.executeQuery(
                  "select t.tbl_name, s.location from tbls t " +
                  "join sds s on t.sd_id = s.sd_id");
              while (rs.next()) {
                  System.out.println(rs.getString(1) + " : " + rs.getString(2));
              }
          }        
  
      }
  }
  </code></pre>