ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## ClickHouse的JDBC连接 1)加入clickhouse-jdbc驱动依赖 ~~~ <dependency> <groupId>ru.yandex.clickhouse<//groupId> <artifactId>clickhouse-jdbc</artifactId> <version>0.1.54</version> </dependency> ~~~ 2)连接操作 ~~~JAVA import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; public class ClickhouseUtils { private static Connection connection = null; static { try { Class.forName("ru.yandex.clickhouse.ClickHouseDriver");// 驱动包 String url = "jdbc:clickhouse://192.168.89.230:8123/default";// url路径 String user = "default";// 账号 String password = "root";// 密码 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 system.functions"); ResultSetMetaData metaData = resultSet.getMetaData(); int columnCount = metaData.getColumnCount(); while (resultSet.next()) { for (int i = 1; i <= columnCount; i++) { System.out.println(metaData.getColumnName(i) + ":" + resultSet.getString(i)); } } } } ~~~