package jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import ru.yandex.clickhouse.ClickHouseDriver;
/**
* @author stjzstart
* @create 2020-10-21 21:43
*/
public class CHJDBC {
public static void main(String[] args) throws Exception {
//注册驱动
Class.forName("ru.yandex.clickhouse.ClickHouseDriver");
//获取连接对象
Connection conn = DriverManager.getConnection("jdbc:clickhouse://hadoop01:8123/default");
//获取执行sql语句对象
String sql = "select * from d_x";
PreparedStatement ps = conn.prepareStatement(sql);
//执行sql语句
ResultSet resultSet = ps.executeQuery();
while (resultSet.next()){
String id = resultSet.getString("id");
String name = resultSet.getString("name");
//String money = resultSet.getString("money");
System.out.println(id+" "+name);
}
}
}