2

javascript を使用して Web インターフェイスを作成し、Cosmos に保存されているデータにアクセスしようとしています。Hive でクエリを作成するために利用できる Java コードがあることは知っています。そのコードを以下に示します。

    private Connection getConnection(
      String ip, String port, String user, String password) {
   try {
      // dynamically load the Hive JDBC driver
      Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver");
   } catch (ClassNotFoundException e) {
      System.out.println(e.getMessage());
      return null;
   } // try catch

   try {
      // return a connection based on the Hive JDBC driver, default DB
      return DriverManager.getConnection("jdbc:hive://" + ip + ":" +
         port + "/default?user=" + user + "&password=" + password);
   } catch (SQLException e) {
      System.out.println(e.getMessage());
      return null;
   } // try catch
} // getConnection


    private void doQuery() {
   try {
      // from here on, everything is SQL!
      Statement stmt = con.createStatement();
      ResultSet res = stmt.executeQuery("select column1,column2," +
         "otherColumns from mytable where column1='whatever' and " +
         "columns2 like '%whatever%'");

      // iterate on the result
      while (res.next()) {
         String column1 = res.getString(1);
         Integer column2 = res.getInteger(2);
         // whatever you want to do with this row, here
      } // while

      // close everything
      res.close(); stmt.close(); con.close();
   } catch (SQLException ex) {
      System.exit(0);
   } // try catch
} // doQuery

そのコードを JavaScript で実装する方法を知る必要があります。それが可能であることはわかっていますが、方法がわかりません。

ありがとう!

4

1 に答える 1