安装hadoop 和 hive我就不多说了,网上太多文章 自己看去
首先,在机器上打开hiveservice
hive --service hiveserver -p 50000 &
打开50000端口,然后java就可以使用java连了,需要的jar包我发个图片
就这多jar包,必须的
不多说,直接上代码
package asia.wildfire.hive.service;
import java.sql.*;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* User: liuxiaochen
* Date: 13-9-24
* Time: 下午5:47
* 修改描述
*/
public class HiveService {
private static final String URLHIVE = "jdbc:hive://ip:50000/default";
private static Connection connection = null;
public static Connection getHiveConnection() {
if (null == connection) {
synchronized (HiveService.class) {
if (null == connection) {
try {
Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver");
connection = DriverManager.getConnection(URLHIVE, "", "");
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
}
return connection;
}
public static void createTable() throws SQLException {
String tweetTableSql = "DROP TABLE IF EXISTS hive_crm_tweet2222";
String createTable1 &