Skip to content

Commit 0509982

Browse files
author
Paultagoras
committed
Update jdbc-v2.md
1 parent f07e7a0 commit 0509982

File tree

1 file changed

+24
-4
lines changed
  • docs/en/integrations/language-clients/java

1 file changed

+24
-4
lines changed

docs/en/integrations/language-clients/java/jdbc-v2.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,33 @@ JDBC Driver supports the same data formats as the underlying [client](/docs/en/i
103103
## Creating Connection
104104

105105
```java
106-
String url = "jdbc:ch://my-server:8123/system"; // use http protocol
106+
String url = "jdbc:ch://my-server:8123/system";
107107

108108
Properties properties = new Properties();
109+
DataSource dataSource = new DataSource(url, properties);//DataSource or DriverManager are the main entry points
110+
try (Connection conn = dataSource.getConnection()) {
111+
... // do something with the connection
112+
```
109113

110-
DataSource dataSource = new DataSource(url, properties);
111-
try (Connection conn = dataSource.getConnection("default", "password");
112-
Statement stmt = conn.createStatement()) {
114+
## Supplying Credentials and Settings
115+
116+
```java showLineNumbers
117+
String url = "jdbc:ch://localhost:8123?jdbc_ignore_unsupported_values=true&socket_timeout=10";
118+
119+
Properties info = new Properties();
120+
info.put("user", "default");
121+
info.put("password", "password");
122+
info.put("database", "some_db");
123+
124+
//Creating a connection with DataSource
125+
DataSource dataSource = new DataSource(url, info);
126+
try (Connection conn = dataSource.getConnection()) {
127+
... // do something with the connection
128+
}
129+
130+
//Alternate approach using the DriverManager
131+
try (Connection conn = DriverManager.getConnection(url, info)) {
132+
... // do something with the connection
113133
}
114134
```
115135

0 commit comments

Comments
 (0)