Last active
March 22, 2023 22:26
-
-
Save subkanthi/c0ddf14b122acf71d17bbd2476945308 to your computer and use it in GitHub Desktop.
Sessions in Clickhouse JDBC (0.3.2-patch11)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/ClickHouse/ClickHouse/blob/58db4b7be4f326f5c30dccf3372172d83912f282/dbms/tests/queries/0_stateless/00463_sessions_in_http_interface.sh | |
// Pass a unique id to session_id and open a new connection. | |
ClickHouseDataSource dataSource = new ClickHouseDataSource(url + "?session_id=1", properties); | |
ClickHouseConnection conn = dataSource.getConnection(userName, ""); | |
dataSource.getConnection().prepareStatement("set max_rows_to_read=7777777").execute(); | |
// Set the setting - max_rows_to_read | |
ResultSet rs = dataSource.getConnection().prepareStatement("select * from system.settings where name='max_rows_to_read'").executeQuery(); | |
while(rs.next()) { | |
String value = rs.getString(2); | |
System.out.println("value"); | |
} | |
// Close connection. | |
conn.close(); | |
// Re-open a new connection with the same session id. | |
ClickHouseDataSource dataSource2 = new ClickHouseDataSource(url + "?session_id=1", properties); | |
ClickHouseConnection conn2 = dataSource2.getConnection(userName, ""); | |
// Check if the max_rows_to_read setting is still set. | |
ResultSet rs2 = conn2.prepareStatement("select * from system.settings where name='max_rows_to_read'").executeQuery(); | |
while(rs2.next()) { | |
String value = rs2.getString(2); | |
System.out.println("value"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment