Skip to main content

JDBC CLI Documentation

JDBC (Java Database Connectivity) is a standard Java API for accessing and managing relational databases. It can be used to execute SQL queries and retrieve results programmatically. Refer to Java Database Connectivity for more details.

The MetricsHub JDBC CLI allows users to connect to databases, execute queries, and retrieve data or perform updates. It supports JDBC-compliant URLs, authentication, and configurable timeouts.

Syntax

jdbccli HOSTNAME --username USERNAME --password PASSWORD --url JDBC_URL --query SQL_QUERY

Options

OptionDescriptionDefault Value
HOSTNAMEHostname or IP address of the database server.None
--urlThe JDBC URL for the database connection. This option is required.None
--usernameUsername for JDBC authentication.None
--passwordPassword for JDBC authentication. If not provided, you will be prompted interactively.None
--queryThe SQL query to execute. This option is required.None
--timeoutTimeout in seconds for SQL query execution.30
-vEnables verbose mode. Use -v for basic logs, -vv for detailed logs.None
-h, --helpDisplays detailed help information about available options.None

Examples

Example 1: Basic SQL Query

jdbccli dev-01 --username admin --password secret --url="jdbc:mysql://dev-01:3306/MyDb" --query="SELECT * FROM users"

Example 2: Basic SQL Query with Interactive Password Input

jdbccli dev-01 --username admin --url="jdbc:postgresql://dev-01:5432/MyDb" --query="SELECT * FROM employees"

The CLI prompts for the password if not provided.

Example 3: Basic SQL Query with Timeout Configuration

jdbccli dev-01 --username admin --password secret --url="jdbc:oracle:thin:@dev-01:1521/MyDb" --query="UPDATE accounts SET balance = balance - 100" --timeout 60