Using SQLline to Test JDBC Connectors
Luke Hebert
- 2 minutes read - 365 wordsWhen you need to see exactly what a SQL client is doing under the hood, rebuilding part of the application to trace it is rarely the fastest path. SQLline gives you a lightweight, command-line way to open a JDBC connection and run queries directly, which makes it ideal for isolating connector behavior from application logic. The steps below walk through downloading the tool, wiring up the classpath, and connecting to an Azure MySQL instance.
Obtain SQLline
While SQLline can be built using Maven, a ready-to-use version is available in the Maven Central Repository.
Be sure to download the version that includes dependencies. For example:
https://repo1.maven.org/maven2/sqlline/sqlline/1.12.0/sqlline-1.12.0-jar-with-dependencies.jar
SQLline Source Code
You will only need this if you intend to build SQLline on your own, but the repository also contains useful usage information.
https://github.com/julianhyde/sqlline
SQLline Documentation
https://julianhyde.github.io/sqlline/manual.html
Obtain the Data Source JDBC Driver
In this example we will use MySQL. You can obtain the JDBC driver from the vendor for the data source you are connecting to, or from a third-party source in cases where the driver is commercial. Prefer platform-independent driver packages or plain JAR file versions. Avoid unpackaged or installer-based drivers.
https://dev.mysql.com/downloads/connector/j/
Upload the SQLline and the Driver
On the host you want to test from, upload the SQLline JAR file and the connector JAR file and place them in the same directory.
If your data source uses TLS, you may need to update the global Java truststore to include the associated CA certificate if it is a non-public CA.
Create a Script to Set Up the Java Class Path
Create a file called sqlline in the same directory as the driver and the SQLline JAR. Then add the following contents.
Create the Script
touch sqllineScript Content
#!/bin/bash
# sqlline - Script to launch SQL shell on Unix, Linux or Mac OS
BINPATH=$(dirname $0)
exec java -cp "$BINPATH/*" sqlline.SqlLine "$@"
# End sqllineMake It Executable
chmod 755 sqllineAzure MySQL Usage Example
# ./sqlline
sqlline version 1.12.0
sqlline> !connect jdbc:mysql://mysqltest.mysql.database.azure.com:3306/mysqltest?verifyServerCertificate=true&useSSL=true&requireSSL=true&username=mduser@mysqltest;
Enter username for jdbc:mysql://mysqltest.mysql.database.azure.com:3306/mysqltest?verifyServerCertificate=true&useSSL=true&requireSSL=true&username=mduser@mysqltest;:
Enter password for jdbc:mysql://mysqltest.mysql.database.azure.com:3306/mysqltest?verifyServerCertificate=true&useSSL=true&requireSSL=true&username=mduser@mysqltest;:
0: jdbc:mysql://mysqltest.mysql.dat> !list
1 active connection: 3
#0 open jdbc:mysql://mysqltest.mysql.database.azure.com:3306/mysqltest?verifyServerCertificate=true&useSSL=true&requireSSL=true&username=mduser@mysqltest;
40: jdbc:mysql://mysqltest.mysql.dat>