{"id":13695654,"url":"https://github.com/Blynk-Technologies/clickhouse4j","last_synced_at":"2025-05-03T13:32:42.427Z","repository":{"id":41063326,"uuid":"203984349","full_name":"Blynk-Technologies/clickhouse4j","owner":"Blynk-Technologies","description":"Lighter and faster alternative for the official ClickHouse JDBC driver","archived":false,"fork":false,"pushed_at":"2023-02-09T07:15:05.000Z","size":1181,"stargazers_count":214,"open_issues_count":21,"forks_count":38,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-11-12T23:36:05.664Z","etag":null,"topics":["java","jdbc-driver"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Blynk-Technologies.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-08-23T11:19:15.000Z","updated_at":"2024-11-05T03:44:59.000Z","dependencies_parsed_at":"2023-12-08T15:05:14.667Z","dependency_job_id":null,"html_url":"https://github.com/Blynk-Technologies/clickhouse4j","commit_stats":null,"previous_names":["blynk-technologies/clickhouse4j","blynkkk/clickhouse4j"],"tags_count":52,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blynk-Technologies%2Fclickhouse4j","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blynk-Technologies%2Fclickhouse4j/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blynk-Technologies%2Fclickhouse4j/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blynk-Technologies%2Fclickhouse4j/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Blynk-Technologies","download_url":"https://codeload.github.com/Blynk-Technologies/clickhouse4j/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252195861,"owners_count":21709724,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","jdbc-driver"],"created_at":"2024-08-02T18:00:31.846Z","updated_at":"2025-05-03T13:32:41.963Z","avatar_url":"https://github.com/Blynk-Technologies.png","language":"Java","funding_links":[],"categories":["Language bindings"],"sub_categories":["Java"],"readme":"Clickhouse4j - lighter and faster alternative for the official ClickHouse JDBC driver\n===============\n\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/cc.blynk.clickhouse/clickhouse4j/badge.svg)](https://mvnrepository.com/artifact/cc.blynk.clickhouse/clickhouse4j) [![clickhouse4j](https://travis-ci.org/blynkkk/clickhouse4j.svg?branch=master)](https://github.com/blynkkk/clickhouse4j)\n\nThe main differences between this and the official driver are:\n\n- Removed Guava, Jackson and Apache Http Client dependencies;\n- Smaller size - 850kb vs 5.6mb of the original driver (**7x smaller jar size**)\n- A bunch of micro optimizations were applied (for example, **batch inserts are now 40% faster**)\n- [CopyManager](https://github.com/blynkkk/clickhouse4j/blob/master/src/main/java/cc/blynk/clickhouse/copy/CopyManager.java) added;\n- Support for JSON, JSONCompact select;\n- Compiled against Java 8 and many [other things](https://github.com/blynkkk/clickhouse4j/blob/master/CHANGELOG)\n\n### Usage\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecc.blynk.clickhouse\u003c/groupId\u003e\n    \u003cartifactId\u003eclickhouse4j\u003c/artifactId\u003e\n    \u003cversion\u003e1.4.4\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### CopyManager usage\n```CopyManager``` is utility class that helps to read / write the queries from / to the file/stream/reader.\n\n##### Select from DB to File\n\n```\nString query = \"SELECT * from copy_manager_test.my_table FORMAT CSVWithNames\";\nPath outputFile = ...;\n\ntry (CopyManager copyManager = CopyManagerFactory.create(dataSource)) {\n    copyManager.copyFromDb(query, outputFile);\n}\n//outputFile now has all the data and headers from the copy_manager_test DB and my_table table\n```\n\n##### Select from DB to File with prepared statement\n\n```\ntry (Connection connection = dataSource.getConnection();\n     PreparedStatement ps = connection.prepareStatement(sql);\n     CopyManager copyManager = CopyManagerFactory.create(connection)) {\n        ps.setLong(1, id);\n        copyManager.copyFromDb(ps, outputStream);\n}\n```\n\n##### Insert from File to DB\n\n```\nString query = \"INSERT INTO copy_manager_test.my_table FORMAT CSV\";\nPath inputFile = ...;\n\ntry (CopyManager copyManager = CopyManagerFactory.create(dataSource)) {\n    copyManager.copyToDb(query, inputFile);\n}\n\n//DB copy_manager_test and my_table table now has all csv data from the inputFile\n```\n\n##### Select as JSON\n\n```\nResultSet rs = connection.createStatement().executeQuery(\"SELECT * FROM test.my_table FORMAT JSON\");\nif (rs.next()) {\n    return rs.getString(\"json\");\n}\n\n//respone example:\n\n{\n\t\"meta\":\n\t[\n\t\t{\n\t\t\t\"name\": \"created\",\n\t\t\t\"type\": \"DateTime\"\n\t\t},\n\t\t{\n\t\t\t\"name\": \"value\",\n\t\t\t\"type\": \"Int32\"\n\t\t}\n\t],\n\n\t\"data\":\n\t[\n\t\t{\n\t\t\t\"created\": \"2019-11-17 11:31:22\",\n\t\t\t\"value\": 1\n\t\t},\n\t\t{\n\t\t\t\"created\": \"2019-11-17 11:31:22\",\n\t\t\t\"value\": 2\n\t\t}\n\t],\n\n\t\"rows\": 2,\n\n\t\"statistics\":\n\t{\n\t\t\"elapsed\": 0.000312306,\n\t\t\"rows_read\": 2,\n\t\t\"bytes_read\": 16\n\t}\n}\n\n```\n\n### Migration from the official driver\n\nAll you need to do is replace:\n\n`ru.yandex.clickhouse.ClickHouseDriver` to `cc.blynk.clickhouse.ClickHouseDriver`\n\nURL syntax: \n`jdbc:clickhouse://\u003chost\u003e:\u003cport\u003e[/\u003cdatabase\u003e]`, e.g. `jdbc:clickhouse://localhost:8123/test`\n\nJDBC Driver Class:\n`cc.blynk.clickhouse.ClickHouseDriver`\n\nadditionally, if you have a few instances, you can use `BalancedClickhouseDataSource`.\n\n### Build requirements\n\nIn order to build the jdbc client one needs to have jdk 1.8 or higher.\n\n### Compiling with maven\n\n`mvn package -DskipTests=true`\n\nTo build a jar with dependencies use\n\n`mvn package assembly:single -DskipTests=true`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBlynk-Technologies%2Fclickhouse4j","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBlynk-Technologies%2Fclickhouse4j","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBlynk-Technologies%2Fclickhouse4j/lists"}