Skip to content

Commit e373707

Browse files
committed
Updated code comments
1 parent 99dfb3f commit e373707

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,17 +204,19 @@ private Map<String, String> parseUrl(String url) throws SQLException {
204204
int lastSlashIndex = pathWithoutLeadingSlash.lastIndexOf('/');
205205

206206
if (lastSlashIndex > 0) {
207-
// Path has multiple segments: everything before last slash is HTTP path
207+
// Path contains a slash (not at position 0), so it has at least two segments.
208+
// Everything before the last slash becomes HTTP path, the last segment is the database.
209+
// Example: "sales/db" -> httpPath="/sales", database="db"
210+
// Example: "api/v1/clickhouse/mydb" -> httpPath="/api/v1/clickhouse", database="mydb"
208211
httpPath = "/" + pathWithoutLeadingSlash.substring(0, lastSlashIndex);
209-
// Decode the database name
210212
try {
211213
database = URLDecoder.decode(pathWithoutLeadingSlash.substring(lastSlashIndex + 1), StandardCharsets.UTF_8.name());
212214
} catch (UnsupportedEncodingException e) {
213215
throw new SQLException("Failed to decode database name", e);
214216
}
215217
} else {
216-
// Single segment: it's the database name, no HTTP path
217-
// Decode the database name
218+
// No slash found (lastSlashIndex == -1), so it's a single segment representing the database name.
219+
// Example: "mydb" -> httpPath="", database="mydb"
218220
try {
219221
database = URLDecoder.decode(pathWithoutLeadingSlash, StandardCharsets.UTF_8.name());
220222
} catch (UnsupportedEncodingException e) {

0 commit comments

Comments
 (0)