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("任务已结束."); } } }
Hive 通过JDBC操作Hive
最新推荐文章于 2024-04-17 17:12:22 发布