hive 版本apache-hive-1.2.1-bin
1.先启动mysql (sevice mysql start),然后启动hive远程服务,输入:./hive --service hiveserver2 即可
然后命令行会显示等待输入,不用管了这里了,进入第二步吧;
2.引入jar包到项目中
jar包包括: apache-hive-1.2.1-bin 里面的lib下的jar包,还有hadoop-2.7.1--》share--》hadoop--》common下的hadoop-common-2.7.1.jar
3.在项目中写入以下代码即可
Class.forName("org.apache.hive.jdbc.HiveDriver");
Connection connection = DriverManager.getConnection("jdbc:hive2://192.168.18.130:10000/hive", "root","root");
连接就创建好了(10000后的hive是hive在mysql中对应的数据库名)
例:
public static void main(String[] args) {
try {
Class.forName("org.apache.hive.jdbc.HiveDriver");
Connection connection = DriverManager.getConnection("jdbc:hive2://192.168.18.130:10000/hive", "root","root");
System.out.println(connection);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
输出结果:
log4j:WARN No appenders could be found for logger (org.apache.hive.jdbc.Utils).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[email protected]
连接成功!!