2024.7.17
springboot hive
jdk17 更换成了 jdk1.8
pom.xml 测试配置 和 hive 连接的依赖
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.7.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>2.1.1</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
<exclusion>
<artifactId>log4j</artifactId>
<groupId>log4j</groupId>
</exclusion>
<exclusion>
<artifactId>log4j-1.2-api</artifactId>
<groupId>org.apache.logging.log4j</groupId>
</exclusion>
<exclusion>
<artifactId>log4j-core</artifactId>
<groupId>org.apache.logging.log4j</groupId>
</exclusion>
<exclusion>
<artifactId>log4j-slf4j-impl</artifactId>
<groupId>org.apache.logging.log4j</groupId>
</exclusion>
<exclusion>
<artifactId>log4j-web</artifactId>
<groupId>org.apache.logging.log4j</groupId>
</exclusion>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<artifactId>jetty-runner</artifactId>
<groupId>org.eclipse.jetty</groupId>
</exclusion>
</exclusions>
</dependency>
简单的测试 连接成功
···java
public class HiveJdbcTest {
public static void main(String[] args) {
String url = "jdbc:hive2://192.168.88.101:10000/myhive";
String username = "hadoop";
String password = "123456";
try (Connection conn = DriverManager.getConnection(url, username, password);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM score")) {
while (rs.next()) {
System.out.println("ID: " + rs.getString("id") + ", Cid: " + rs.getString("cid") + ", Score: " +
rs.getInt("score") + ",month: " + rs.getString("month"));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
发现用 select * from score 查出来的结果全部都是null
select id, cid, score, month from score 这个可以查出来