{"id":18743086,"url":"https://github.com/kxsystems/jdbc","last_synced_at":"2025-04-12T21:24:25.228Z","repository":{"id":59165623,"uuid":"533785390","full_name":"KxSystems/jdbc","owner":"KxSystems","description":"JDBC client for kdb+","archived":false,"fork":false,"pushed_at":"2025-03-07T16:39:34.000Z","size":36747,"stargazers_count":3,"open_issues_count":1,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-08T21:02:18.730Z","etag":null,"topics":["java","jdbc","kdb"],"latest_commit_sha":null,"homepage":"https://code.kx.com/q","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KxSystems.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-07T13:46:40.000Z","updated_at":"2025-02-24T13:39:11.000Z","dependencies_parsed_at":"2024-05-21T16:52:51.572Z","dependency_job_id":null,"html_url":"https://github.com/KxSystems/jdbc","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KxSystems%2Fjdbc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KxSystems%2Fjdbc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KxSystems%2Fjdbc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KxSystems%2Fjdbc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KxSystems","download_url":"https://codeload.github.com/KxSystems/jdbc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248633005,"owners_count":21136788,"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","kdb"],"created_at":"2024-11-07T16:09:58.677Z","updated_at":"2025-04-12T21:24:25.222Z","avatar_url":"https://github.com/KxSystems.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JDBC client for kdb+\n\n\u003e :warning: **Depends on Java interface**\n\u003e\n\u003e Compilation depends on version 1 of the Java interface\n\u003e [KxSystems/javakdb](https://github.com/KxSystems/javakdb/releases/tag/1.0).\n\n\u003e **Implementation**\n\u003e\n\u003e This is a pure Java native-protocol driver (type 4) JDBC driver. The implementation builds on the lower-level [javakdb API](https://github.com/KxSystems/javakdb), whic\nh is somewhat simpler, and a good choice for application development when support for legacy code is not a consideration.\n\nThe JDBC driver implements only the minimal core of the JDBC feature set. \n\nThere is no significant difference in performance between using the `!PreparedStatement`, `!CallableStatement` or `Statement` interfaces.\n\nQ does not have the concept of transactions as expected by the JDBC API. \nThat is, you cannot open a connection, explicitly begin a transaction, issue a series of separate queries within that transaction and finally roll back or commit the transaction. \nIt will always behave as if `autoCommit` is set to true and the transaction isolation is set to `SERIALIZABLE`.\nIn practice, this means that any single query (or sequence of queries if executed in a single JDBC call) will be executed in isolation without noticing the effects of other queries, and modifications made to the database will always be permanent.\n\nOperations must be prefixed by `\"q)\"` in order to be executed as q statements. \n\n## Building from source\n\n### Prerequisites\n\n-   Java 1.8+ is recommended\n\n\tEnsure your `JAVA_HOME` environment variable is set to the version of Java you have installed (or the one preferred if you have multiple versions).\n\n-   [Apache Maven](https://maven.apache.org/)\n\n\tRun the following to check you have it setup and configured correctly.\n\n\t```bash\n\tmvn -version\n\t```\n-\t[javakdb interface](https://github.com/KxSystems/javakdb)\n\n\n### Build\n\nTo build the library, run the following within the directory where the `pom.xml` file is located (from the downloaded source). \n\n```bash\nmvn clean compile\n```\n\nTo deploy the library to your machine’s local repository (e.g. for use by other Maven projects on your machine), run the following\n\n```bash\nmvn clean install\n```\n\n:globe_with_meridians:\n[Apache Maven documentation](https://maven.apache.org/guides) \n\n\n## Code example\n\nThe following describes, each with an example, how to run from Maven. (Maven is not required to run the applications, but used here for convenience.)\n\nThe example remotely creates a table `t`, then queries kdb+ for its contents, and then displays its columns/data to the console.\n\nRun `mvn clean install`.\n\nThe JDBC driver passes the q or SQL text to the server. \nFor SQL support, take the `ps.k` file from the [ODBC3 zip file](https://code.kx.com/q/interfaces/q-server-for-odbc3/)\nand ensure that is loaded into your kdb+ process. ps.k is the sql transpiler or enquire about SQL support with KX Insights. The example requires kdb+ to be listening on TCP port 5001\n\nExample1 shows executing inserts with types and general select\n\n```mvn exec:java -pl jdbc-example -Dexec.mainClass=\"com.kx.jdbcexamples.Example1\" -q```\n\nExample2 show running a q function and converting results to their appropriate types\n\n```mvn exec:java -pl jdbc-example -Dexec.mainClass=\"com.kx.jdbcexamples.Example2\" -q```\n\n## Connection pooling\n\nIf little work is being performed per interaction via the JDBC driver,\nthat is, few queries and each query is very quick to execute,\nthen there is a significant advantage to using connection pooling.\n\nUsing the [Apache Commons DBCP](https://commons.apache.org/proper/commons-dbcp/) component improves the performance of this case by about 70%.\nDBCP avoids some complexity which can be introduced by other connection pool managers.\nFor example, it handles connections in the pool that have become invalid (say due to a database restart) by automatically reconnecting.\nFurthermore it offers configuration options to check the status of connections in the connection pool using a variety of strategies.\n\nAlthough it is not necessary to call the `close` method on `!ResultSet`, `Statement`, `!PreparedStatement` and `!CallableStatement` when using the q JDBC driver,\nit is recommended with the DBCP component as it performs checks to ensure all resources are cleaned up, and has the ability to report resource leaks.\nExplicitly closing the resources avoids a small runtime cost.\n\n```java\n#!java\n\nimport org.apache.commons.pool2.ObjectPool;\nimport org.apache.commons.pool2.impl.GenericObjectPool;\nimport org.apache.commons.dbcp2.ConnectionFactory;\nimport org.apache.commons.dbcp2.DriverManagerConnectionFactory;\nimport org.apache.commons.dbcp2.PoolableConnection;\nimport org.apache.commons.dbcp2.PoolableConnectionFactory;\nimport org.apache.commons.dbcp2.PoolingDataSource;\n\n...\n\nClass.forName(\"com.kx.jdbc\");\n\n// A ConnectionFactory is used by the to create Connections.\n// This example uses the DriverManagerConnectionFactory, with a\n// a connection string for a local q database listening on port 5001.\n//\nConnectionFactory connectionFactory =\n            new DriverManagerConnectionFactory(\"jdbc:q:localhost:5001\",null);\n\n// A PoolableConnectionFactory is used to wrap the Connections\n// created by the ConnectionFactory with the classes that implement\n// the pooling functionality.\n//\nPoolableConnectionFactory poolableConnectionFactory = new \n            PoolableConnectionFactory(connectionFactory, null);\n\n// An ObjectPool serves as the pool of connections.\nObjectPool\u003cPoolableConnection\u003e connectionPool = new \n            GenericObjectPool\u003c\u003e(poolableConnectionFactory);\n\n// Set the factory's pool property to the owning pool\npoolableConnectionFactory.setPool(connectionPool);\n\n// Now we can get a data source as before\nPoolingDataSource\u003cPoolableConnection\u003e dataSource = new \n            PoolingDataSource\u003c\u003e(connectionPool);\n\n// As we use/close connections, we can see the number\n// of underlying instances in the pool\njava.sql.Connection c1=dataSource.getConnection();\njava.sql.Connection c2=dataSource.getConnection();\nc2.close();\n\nSystem.out.println(\"num active \"+connectionPool.getNumActive());\nSystem.out.println(\"num idle \"+connectionPool.getNumIdle());\n```\n\n## SSL/TLS connections\n\nConnections can be encrypted via SSL/TLS by setting the connection property `ssl` to the string value `true`.\nFor example:\n\n```java\nProperties props = new Properties();\nprops.setProperty(\"user\", \"my_user\");\nprops.setProperty(\"password\", \"my_password\");\nprops.setProperty(\"ssl\", \"true\");\nh = DriverManager.getConnection(\"jdbc:q:localhost:5001\",props);\n```\n\nThe connection may require certificates/keys to registered via JSSE (as referenced [here](https://github.com/KxSystems/javakdb/tree/master/docs#ssltls))\nand the kdb+ server to be configured to accept SSL/TLS connections.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkxsystems%2Fjdbc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkxsystems%2Fjdbc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkxsystems%2Fjdbc/lists"}