JAva操作hive
my.propertiesプロファイル
プロファイル読み込みツールクラス:
hive操作ツールクラスおよびテスト:
pom.xmlファイル依存性は、自分の環境に対応するバージョンに注意してください.
# hive
hive_driverClassName=org.apache.hive.jdbc.HiveDriver
hive_url=jdbc:hive2://192.168.10.154:10000
hive_user=root
hive_password=123456
# hive
hive_jichuku=jichuku
プロファイル読み込みツールクラス:
package utils;
import java.io.FileInputStream;
import java.util.Properties;
public class ProperUtil {
private static Properties properties = new Properties();
static {
String path = Thread.currentThread().getContextClassLoader().getResource("my.properties").getPath();
try {
properties.load(new FileInputStream(path));
} catch (Exception e) {}
}
public static String getProperty(String key) {
return properties.getProperty(key);
}
public static void setProperty(String key, String value) {
properties.setProperty(key, value);
}
}
hive操作ツールクラスおよびテスト:
package utils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class HiveUtil {
public static void main(String args[]) {
String sql = "select * from back_xf_user where del_flg=?";
List
pom.xmlファイル依存性は、自分の環境に対応するバージョンに注意してください.
2.1.0
2.7.6
org.apache.hive
hive-jdbc
${hive.version}
org.apache.hadoop
hadoop-common
${hadoop.version}