chdb-java-ffm is Java 22+ JEP 454: Foreign Function & Memory API bind for chdb.
- Please add the following dependency to
pom.xml
:
<dependency>
<groupId>org.mvnsearch</groupId>
<artifactId>chdb-java-ffm</artifactId>
<version>0.2.0</version>
</dependency>
- Download chdb dynamic library by executing
update_libchdb.sh
script, or download from https://github.com/chdb-io/chdb/releases. - Write your first test:
public class ChdbConnectionTest {
@AutoClose
private static Connection conn;
@BeforeAll
public static void setUp() throws Exception {
String url = "jdbc:chdb::memory:";
conn = DriverManager.getConnection(url);
}
@Test
public void testConnection() throws SQLException {
String sql = "select * from file('src/test/resources/logs.csv','CSV')";
Statement statement = conn.createStatement();
ResultSet resultSet = statement.executeQuery(sql);
while (resultSet.next()) {
System.out.println(resultSet.getString("level"));
}
}
}
JDBC URLs:
jdbc:chdb::memory:
: in-memory database, path is:memory:
jdbc:chdb:/path/to/db
: database from file path, and both relative and absolute paths supported.
- Download and install JDK 22
- Download and install jextract
- Execute
update_libchdb.sh
to download dynamic library
Execute ln -s /usr/local/lib/libchdb.so libchdb.dylib
to link the dynamic library to the current directory.
Now only query support, and update will be implemented in the future.
Now PreparedStatement implement is not real, just fake implement friendly for libraries and frameworks.
Yes, you can use JdbcTemplate
with chdb-java-ffm.
Java -> FFM -> chdb(embedded) -> JSON Output -> ResultSet.
Attention: chdb-java-ffm uses Jackson for JSON parsing.
- JEP 454: Foreign Function & Memory API
- jextract: a tool which mechanically generates Java bindings from native library headers
- chdb-java: chdb JNI version
- clickhouse-java: Java client and JDBC driver for ClickHouse