目录
程序代码如下:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
/**
* @author pangsl
* @date 2021/7/15 16:13
* @Description java连接clickhouse查询数据打印
*/
public class XingNeng_Test {
private static Connection connection = null;
static {
try {
Class.forName("ru.yandex.clickhouse.ClickHouseDriver");// 驱动包
String url = "jdbc:clickhouse://10.130.22.51:8123/zkkk_app";
String user = "ddd";
String password = "aaae_123";
connection = DriverManager.getConnection(url,user,password);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws SQLException {
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("select * from zkkk_app.cust_no ctb where cust_no = '3004104445587'");
ResultSetMetaData metaData = resultSet.getMetaData();
int columnCount = metaData.getColumnCount();
System.out.println(columnCount);
while (resultSet.next()){
for (int i =1;i <= columnCount;i ++){
System.out.println(metaData.getColumnName(i) + ":" + resultSet.getString(i));
}
}
}
}
运行结果如下: