`
qingwei201314
  • 浏览: 163196 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Hive 通过JDBC操作Hive

 
阅读更多
package com.kevin.job;

        import org.springframework.stereotype.Service;
        import org.springframework.scheduling.annotation.Scheduled;
        import java.sql.*;

@Service
public class HiveJob {
    private static int i = 1;

@Scheduled(fixedDelay = 1000)
    public void partition() throws ClassNotFoundException, SQLException {
        try {
            Class.forName("org.apache.hive.jdbc.HiveDriver");
} catch (ClassNotFoundException e) {
            throw e;
}
        if( i == 1 ){
            Connection con = DriverManager.getConnection("jdbc:hive2://192.168.86.130:10000/default", "root", "");
Statement stmt = con.createStatement();

System.out.println("开始创建分区");
String sql = "insert into canal_p partition(pt = 2000000) select * from canal where id >= 1000000 and id < 2000000";
System.out.println("Running: " + sql);
            boolean res = stmt.execute(sql);
System.out.println("res:" + res);
System.out.println("结束创建分区");
i ++ ;
} else {
            System.out.println("任务已结束.");
}
    }
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics