Java SQL Shell (JSqsh)
You can use IBM® Big SQL from any client tool that uses a JDBC or ODBC driver. One of those clients is the Java SQL Shell (JSqsh) command interface. When you run the jsqsh command from the command line, you open a command shell. You can type specific Db2 Big SQL commands or statements into this shell and view output from Db2 Big SQL queries.
The JSqsh interface is a generic JDBC client. You can use JSqsh with any data source for which a JDBC driver is available
More JSqsh documentation
For JSqsh setup information see Accessing Db2 Big SQL from the JSqsh client.
\help commands
\help vars
Running JSqsh
./jsqsh
to open the JSqsh
shell:cd /usr/ibmpacks/common-utils/current/jsqsh/bin
./jsqsh
You can then run
any JSqsh commands from the prompt. Connection setup
- The first time that you open the JSqsh command shell, a configuration wizard is started. When
you are at the Jsqsh command prompt, type \drivers to determine the available drivers.
- On the driver selection screen, select the Db2 Big SQL instance that you want to runNote: Db2 Big SQL is designated as DB2 in this example:
Name Target Class - ------- ------------------- -------------------------------------------- ... 2 *db2 IBM Data Server(DB2 com.ibm.db2.jcc.DB2Driver
- Verify the port, server, and user name. Run \setup and click C to define a password for the connection. The username must have database administration privileges, or must be granted those privileges by the Db2 Big SQL administrator.
- Test the connection to the Db2 Big SQL server.
- Save and name this connection.
- On the driver selection screen, select the Db2 Big SQL instance that you want to run
- Generally, you can access JSqsh from
/usr/ibmpacks/common-utils/current/jsqsh/bin with the following
command:
./jsqsh --driver=db2 --user=<username> --password=<user_password>
- Open the saved configuration wizard any time by typing
\setup
while in the command interface, or./jsqsh --setup
when you open the command interface. - Specify the following connection name in the JSqsh command shell to establish a connection:
./jsqsh name
- Use the
\connect
command when you are already inside the JSQSH shell to establish a connection at the JSqsh prompt:\connect name
Commands and queries
At the JSqsh command prompt, you can run JSqsh commands or database server commands. JSqsh commands usually begin with a backslash (\) character.
JSqsh commands accept command-line arguments and allow for common shell activities, such as I/O redirection and pipes.
1> select * from t1
2> where c1 > 10
3> \go -m csv > /tmp/t1.csv
Because the commands do not begin with a backslash character, the first two commands are assumed to be SQL statements, and are sent to the Db2 Big SQL server.
1> select * from t1
2> where c1 > 10;
The --style option in the \go command indicates that the display shows comma-separated values (CSV). The \go form is most useful if you provide additional arguments to affect how the query is run. Changing the display style is an example of this feature.
The redirection operator (>) specifies that the results of the command are sent to a file called /tmp/t1.csv.
\alias bye='\quit'
select tabschema, tabname from syscat.tables fetch first 5 rows only;
select tabschema, colname, colno, typename, length from syscat.columns fetch first 10 rows only;
You
can start JSqsh and run the script at the same time with this
command:/usr/ibmpacks/common-utils/current/jsqsh/bin/jsqsh bigsql < /home/bigsql/mySQL.sql
The
redirection operator specifies to JSqsh to get the commands from the file located in the
/home/bigsql directory, and then run the statements within the file.Command and query edit
The JSqsh command shell uses the JLine2 library, which allows you to edit previously entered commands and queries. You use the command-line edit features to move the arrow keys and to edit the command or query on the current line.
The JLine2 library provides the same key bindings (vi and emacs) as the GNU Readline library. In addition, it attempts to apply any custom key maps that you created in a GNU Readline configuration file, (.inputrc) in the local file system $HOME/ directory.
1> \history
(1) use tpch;
(2) select count(*) from lineitem
1> !2
1> select count(*) from lineitem
2>
- !!
- Recalls the previously run statement.
- !5
- Recalls the fifth query from history.
- !-2
- Recalls the query from two prior runs.
1> select id, count(*)
2> from t1, t2
3> where t1.c1 = t2.c2
4> \buf-edit
The query is opened in an external editor (/usr/bin/vi by default. However, you can specify a different editor on the environment variable $EDITOR). When you close the editor, the edited query is entered at the JSqsh command shell prompt.
1> select id, count(*)
2> from t1, t2
3> where t1.c1 = t2.c2
4> vi
Configuration variables
1> \set
1> \set prompt='foo $lineno> '
foo 1>
1> \help prompt
If you want to permanently set a specific variable, you can do so by editing your $HOME/.jsqsh/sqshrc file and including the appropriate \set command in it.