A CLI swiss-army knife for jdbc with batch and interactive mode
Jdbsee is tool providing database access from command line using JDBC.
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.
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 orTAB
to navigate through available commands, or type some chars to filter by name -
hit
ENTER
to automatically type the selected command, thenENTER
again to execute it orTAB
for further hints
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 hitENTER
to exit
Invoke the jdbsee
executable passing appropriate commands and params.
jdbsee help
provides the main help. jdbsee COMMAND help
provides
the help for COMMAND.
See the list of supported commands for more details.
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;"
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;"
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;"
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)
-
Build project
-
invoke the
run
command -
execute create table DDL
-
add some data
-
define jdbc url
-
specify select query
you should get
┌───────────────────────────────────────┬──────────────────────────────────────┐
│ID │NAME │
├───────────────────────────────────────┼──────────────────────────────────────┤
│1 │Alice │
├───────────────────────────────────────┼──────────────────────────────────────┤
│2 │Bob │
├───────────────────────────────────────┼──────────────────────────────────────┤
│3 │John │
├───────────────────────────────────────┼──────────────────────────────────────┤
│4 │Daisy │
└───────────────────────────────────────┴──────────────────────────────────────┘
./gradlew release \
-Prelease.versionIncrementer=incrementMinor \
-Prelease.dryRun \
-Prelease.customUsername="..." -Prelease.customPassword="..."