写的不到位的地方,欢迎评论指出不足之处
数据
192.168.1.4 - - [20/Jul/2021:9:20:30 +0800] "GET /1.png HTTP/1.1" 304 -
192.168.1.4 - - [20/Jul/2021:9:20:30 +0800] "GET /1.PNG HTTP/1.1" 304 -
192.168.1.4 - - [20/Jul/2021:9:20:31 +0800] "GET /1.jpg HTTP/1.1" 304 -
192.168.1.4 - - [20/Jul/2021:9:20:31 +0800] "GET /1.JPG HTTP/1.1" 304 -
192.168.1.4 - - [20/Jul/2021:9:20:32 +0800] "GET /1.css HTTP/1.1" 304 -
192.168.1.4 - - [20/Jul/2021:9:20:32 +0800] "GET / HTTP/1.1" 200 11217
192.168.1.4 - - [20/Jul/2021:9:20:33 +0800] "GET /1.mp4 HTTP/1.1" 304 -
192.168.1.4 - - [20/Jul/2021:9:20:33 +0800] "GET /1.html HTTP/1.1" 304 -
192.168.1.4 - - [20/Jul/2021:9:20:34 +0800] "GET /1.gif HTTP/1.1" 304 -
192.168.1.4 - - [20/Jul/2021:9:20:34 +0800] "GET / HTTP/1.1" 200 11217
hive 中的数据
hive 需要启动 hiveserver2 服务
对非开发者人员提供,只是查询,而且 hive 也只是对内使用,所以密码无所谓(具体查看上一章内容),不要纠结
JDBC 代码
package com.my.hive.demo;
import java.sql.*;
public class HiveJdbcClient {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("org.apache.hive.jdbc.HiveDriver");
Connection conn = DriverManager.getConnection("jdbc:hive2://three:10000/default", "root", "123456");
Statement stmt = conn.createStatement();
String sql = "select * from logtbl";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
System.out.println("字段:" + " - " +
rs.getString("host") + " - " +
rs.getString("time") + " - " +
rs.getString("request") + " - " +
rs.getInt("referer") + " - " +
rs.getString("agent")
);
System.out.println("索引:" + " - " +
rs.getString(1) + " - " +
rs.getString(4) + " - " +
rs.getString(5) + " - " +
rs.getInt(6) + " - " +
rs.getString(7)
);
System.out.println("-----------------------------------");
}
rs.close();
stmt.close();
}
}
Maven 的 pom.xml
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>2.3.4</version>
</dependency>