package org.example;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.UUID;
public class Main {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
try {
Class.forName("com.clickhouse.jdbc.ClickHouseDriver");
String url = "jdbc:clickhouse://xx.xxx.x.xx:xxxx/xxxxx";
String user = "xx_xxxxx";
String password = "xxxxxx";
Connection conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement();
String query = "SELECT * FROM xxxxx where (node7 <> '' and node8 = '' or node2 <> '' and node3 = '') and partition_date='2023-09-10'";
ResultSet rs = stmt.executeQuery(query);
// 将查询结果写入本地文件
FileWriter fileWriter = new FileWriter("C:\\Users\\xxxxx\\Desktop\\clickHouseIn.txt");
PrintWriter printWriter = new PrintWriter(fileWriter);
while (rs.next()) {
String assy_id = rs.getString(1);
String removed = rs.getString(2);
String partition_date = rs.getString(3);
String node1 = rs.getString(4);
String node2 = rs.getString(5);
String node3 = rs.getString(6);
String node4 = rs.getString(7);
String node5 = rs.getString(8);
String node6 = rs.getString(9);
String node7 = rs.getString(10);
// 将数据写入文件
printWriter.println(assy_id + "\t" + removed + "\t" + partition_date + "\t" + node1 + "\t" + node2 + "\t" + node3 + "\t" + node4 + "\t" + node5 + "\t" + node6 + "\t" + node7);
}
printWriter.close();
fileWriter.close();
conn.close();
} catch (SQLException | ClassNotFoundException | IOException e) {
e.printStackTrace();
}
}
}
jdbc读取clickhouse数据落地成本地文件
最新推荐文章于 2024-08-09 07:23:07 发布