Skip to content

davidecavestro/jdbsee

Repository files navigation

JDBSEE - CLI

Build Status (Travis CI) Coverage Status (Coveralls) GitHub commit activity GitHub code size in bytes

GitHub release Github commits (since latest release)

A CLI swiss-army knife for jdbc with batch and interactive mode

Jdbsee is tool providing database access from command line using JDBC.

Features

Jdbsee CLI supports executing SQL queries from command line and exporting retrieved data.

The JDBC drivers can be automatically downloaded or loaded from jars on filesystem.
Database connection settings and related credentials can be persisted for later reuse.

The user interface supports both batch and interactive shell mode.

For more info please see the documentation.

Usage

Interactive mode

Open the interactive shell and execute multiple commands within the application:

  • type jdbsee shell to open the interactive shell

  • hit TAB to get a list of available commands

  • use left/right arrows or TAB to navigate through available commands, or type some chars to filter by name

  • hit ENTER to automatically type the selected command, then ENTER again to execute it or TAB for further hints

Jdbsee shell message

In order to execute multiple queries within the same sql session:

  • use the jdbsee connect command to open the interactive sql session (i.e. jdbsee connect -d "com.h2database:h2:1.4.196" -l "jdbc:h2:mem:test")

  • type your query and hit ENTER for every query

  • use up/down arrows to navigate into the history

  • type quit and hit ENTER to exit

Jdbsee connect message

Batch mode

Invoke the jdbsee executable passing appropriate commands and params. jdbsee help provides the main help. jdbsee COMMAND help provides the help for COMMAND.

Jdbsee help message

See the list of supported commands for more details.

Examples

Automatic downloading drivers

Use the -d switch to automatically download drivers

./bin/jdbsee run -u postgres -p postgres \
  -d "org.postgresql:postgresql:42.2.1" \
  -l "jdbc:postgresql://localhost:5432/test" \
  "SELECT * FROM contacts;"

Loading drivers from external jars

Use the -j switch to load drivers from filesystem

./bin/jdbsee run -u postgres -p postgres \
  -j "/path/to/postgresql.jar" \
  -l "jdbc:postgresql://localhost:5432/test" \
  "SELECT * FROM contacts;"

Loading drivers from the dropins subfolder

Copy your jdbc driver jars into the app distribution under the dropins folder, and they will be scanned for jdbc drivers

./bin/jdbsee run -u postgres -p postgres \
  -l "jdbc:postgresql://localhost:5432/test" \
  "SELECT * FROM contacts;"

How to build

The build system supports producing the distribution of the application both with or without drivers.

The main distribution comes without drivers, while the full provides drivers within the dropins folder.

The following command generates both main and full distribution archives

./gradlew fullDistTar fullDistZip distTar distZip

the generated archives are located into the build/distributions subfolder

build/distributions/
├── jdbsee-x.y.z-SNAPSHOT.tar
├── jdbsee-x.y.z-SNAPSHOT.zip
├── jdbsee-full-x.y.z-SNAPSHOT.tar
└── jdbsee-full-x.y.z-SNAPSHOT.zip

Follows an example on how to build with drivers (full distribution) and launch some queries on an in-memory h2 db

./gradlew installFullDist && \ //(1)
./build/install/jdbsee-full/bin/jdbsee run \ //(2)
-x "create table contacts (id int primary key, name varchar(100));" \ //(3)
-x "insert into contacts (id, name) values (1, 'Alice');" \ //(4)
-x "insert into contacts (id, name) values (2, 'Bob');" \
-x "insert into contacts (id, name) values (3, 'John');" \
-x "insert into contacts (id, name) values (4, 'Daisy');" \
-d "com.h2database:h2:1.4.196" \
-l "jdbc:h2:mem:test" \ //(5)
"SELECT * FROM contacts;" //(6)
  1. Build project

  2. invoke the run command

  3. execute create table DDL

  4. add some data

  5. define jdbc url

  6. specify select query

you should get

┌───────────────────────────────────────┬──────────────────────────────────────┐
│ID                                     │NAME                                  │
├───────────────────────────────────────┼──────────────────────────────────────┤
│1                                      │Alice                                 │
├───────────────────────────────────────┼──────────────────────────────────────┤
│2                                      │Bob                                   │
├───────────────────────────────────────┼──────────────────────────────────────┤
│3                                      │John                                  │
├───────────────────────────────────────┼──────────────────────────────────────┤
│4                                      │Daisy                                 │
└───────────────────────────────────────┴──────────────────────────────────────┘

How to release

./gradlew release \
-Prelease.versionIncrementer=incrementMinor \
-Prelease.dryRun  \
-Prelease.customUsername="..." -Prelease.customPassword="..."