5. Command line parameters

5.1. Specify the directory for configuration settings
5.2. Specify a base directory for JDBC driver libraries
5.3. Specify the file containing connection profiles
5.4. Defining variables
5.5. Prevent updating the .settings file
5.6. Connect using a pre-defined connection profile
5.7. Connect without a profile

Command line parameters are not case sensitive. The parameters -PROFILE or -profile are identical. The usage of the command line parameters is identical between the launcher or starting SQL Workbench/J using the java command itself.

[Note]

When quoting parameters on the command line (especially in a Windows® environment) you have to use single quotes, as the double quotes won't be passed to the application.

5.1. Specify the directory for configuration settings

The parameter -configDir specifies the directory where SQL Workbench/J will store all its settings. If this parameter is not supplied, the directory where the default location is used. The placeholder ${user.home} will be replaced with the current user's home directory (as returned by the Operating System). If the specified directory does not exist, it will be created.

If you want to control the location where SQL Workbench/J stores the configuration files, you have to start the application with the parameter -configDir to specify an alternate directory:

java -jar sqlworkbench.jar -configDir=/export/configs/SQLWorkbench

or if you are using the Windows® launcher:

SQLWorkbench -configDir=c:\ConfigData\SQLWorkbench

The placeholder ${user.home} will be replaced with the current user's home directory (as returned by the Operating System), e.g.:

java -jar sqlworkbench.jar -configDir=${user.home}/.sqlworkbench

If the specified directory does not exist, it will be created.

On the Windows® platform you can use a forward slash to separate directory names in the parameter.

5.2. Specify a base directory for JDBC driver libraries

The -libdir parameter defines the base directory for your JDBC drivers. The value of this parameter can be referenced when defining a driver library using the placeholder %LibDir% The value for this parameter can also be set in the file workbench.settings.

5.3. Specify the file containing connection profiles

SQL Workbench/J stores the connection profiles in a file called WbProfiles.xml. If you want to use a different filename, or use different set of profiles for different purposes you can define the file where the profiles are stored with the -profileStorage parameter.

If the value of the parameter does not contain a path, the file will be expected (and stored) in the configuration directory.

The default XML format of the WbProfiles.xml file is not intended to be edited manually. To manage pre-defined profiles for console mode or batch mode, it's easier to use a properties file containing the profiles.

When specifying a properties file with -profileStorage the file extension must be .properties

5.4. Defining variables

You can define variables when starting SQL Workbench/J by either passing the variable definition directly or by passing a file that contains the variable definitions.

Defining variable values in this way can also be used when running in batch mode.

Providing a file with variable definitions

With the -varFile parameter a definition file for internal variables can be specified. Each variable has to be listed on a single line in the format variable=value. Lines starting with a # character are ignored (comments). the file can contain unicode sequences (e.g. \u00fc. Values spanning multiple lines are not supported. When reading a file during startup the default encoding is used. If you need to read the file in a specific encoding please use the WbVarDef command with the -file and -encoding parameter.

#Define some values
var_id=42
person_name=Dent
another_variable=24

If the above file was saved under the name vars.txt, you can use those variables by starting SQL Workbench/J using the following command line:

java -jar sqlworkbench.jar -varFile=vars.txt

Specifying variables directly

A single variable can be defined by passing the parameter -variable. This parameter can be supplied multiple times to define multiple variables:

java -jar sqlworkbench.jar -variable=foo=42 -variable=bar='xyz'

Note that the variable definition does not need to be quoted even though it contains the = character. Using -variable=bar='xyz' will include the single quotes in the variable value. The variable definition only needs to be quoted if it contains a space:

java -jar sqlworkbench.jar -variable="foo=hello world"

5.5. Prevent updating the .settings file

If the -nosettings parameter is specified, SQL Workbench/J will not write its settings to the file workbench.settings when it's beeing closed. Note that in batch mode, this file is never written.

[Note]

If this parameter is supplied, the workspace will not be saved automatically as well!

5.6. Connect using a pre-defined connection profile

You can specify the name of an already created connection profile on the command line with the -profile=<profile name> parameter. The name has to be passed exactly like it appears in the profile dialog (case sensitive!). If the name contains spaces or dashes, it has to be enclosed in quotations marks. If you have more than one profile with the same name but in different profile groups, you have to specify the desired profile group using the -profilegroup parameter, otherwise the first profile matching the passed name will be selected.

Example (on one line):

java -jar sqlworkbench.jar
     -profile='PostgreSQL - Test'
     -script='test.sql'

In this case the file WbProfiles.xml must be in the current (working) directory of the application. If this is not the case, please specify the location of the profile using either the -profileStorage or -configDir parameter.

If you have two profiles with the names "Oracle - Test" you will need to specify the profile group as well (in one line):

java -jar sqlworkbench.jar
     -profile='PostgreSQL - Test'
     -profilegroup='Local'
     -script='test.sql'

You can also store the connection profiles in a properties file and specify this file using the -profileStorage parameter.

5.7. Connect without a profile

You can also specify the full connection parameters on the command line, if you don't want to create a profile only for executing a batch file. The advantage of this method is, that SQL Workbench/J does not need the files WbProfiles.xml, WbDrivers.xml to be able to connect to the database.

Specifying all connection attributes

ParameterDescription
-urlThe JDBC connection URL
-usernameSpecify the username for the DBMS
-password

Specify the password for the user

If this parameter is not specified (but -url and -username) then you will be prompted to enter the password. To supply an empty password use -password= in the command line when starting SQL Workbench/J

-driverSpecify the full class name of the JDBC driver
-driverJarSpecify the full pathname to the .jar file containing the JDBC driver
-autocommitSet the autocommit property for this connection. You can also control the autocommit mode from within your script by using the SET AUTOCOMMIT command.
-rollbackOnDisconnectIf this parameter is set to true, a ROLLBACK will be sent to the DBMS before the connection is closed. This setting is also available in the connection profile.
-checkUncommitted If this parameter is set to true, SQL Workbench/J will try to detect uncommitted changes in the current transaction when the main window (or an editor panel) is closed. If the DBMS does not support this, this argument is ignored. It also has no effect when running in batch or console mode.
-trimCharData Turns on right-trimming of values retrieved from CHAR columns. See the description of the profile properties for details.
-removeCommentsThis parameter corresponds to the Remove comments setting of the connection profile.
-fetchSizeThis parameter corresponds to the Fetch size setting of the connection profile.
-ignoreDropErrorThis parameter corresponds to the Ignore DROP errors setting of the connection profile.
-altDelimiter This parameter corresponds to the Alternate delimiter setting of the connection profile.
-emptyStringIsNullThis parameter corresponds to the Empty String is NULL setting of the connection profile. This will only be needed when editing a result set in GUI mode.
-connectionProperties

This parameter can be used to pass extended connection properties if the driver does not support them e.g. in the JDBC URL. The values are passed as key=value pairs, e.g. -connectionProperties=someProp=42

If either a comma or an equal sign occurs in a parameter's value, it must be quoted. This means, when passing multiple properties the whole expression needs to be quoted: -connectionProperties='someProp=42,otherProp=24'.

As an alternative, a colon can be used instead of the equals sign, e.g -connectionProperties=someProp:42,otherProp:24. In this case no quoting is needed (because no delimiter is part of the parameters value).

If any of the property values contain a comma or an equal sign, then the whole parameter value needs to be quoted again, even when using a colon. -connectionProperties='someProp:"answer=42",otherProp:"2,4"' will define the value answer=42 for the property someProp and the value 2,4 for the property otherProp.

-altDelim The alternate delimiter to be used for this connection. e.g. -altDelimiter=GOl to define a SQL Server like GO as the alternate delimiter. Note that when running in batchmode you can also override the default delimiter by specifying the -delimiter parameter.
-separateConnectionIf this parameter is set to true, and SQL Workbench/J is run in GUI mode, each SQL tab will use it's own connection to the database server. This setting is also available in the connection profile. The default is true.
-connectionName When specifying a connection without a profile (only using -username, -password and so on) then the name of the connection can be defined using this parameter. The connection name will be shown in the title of the main window if SQL Workbench/J is started in GUI mode. The parameter does not have any visible effect when running in batch or console mode.
-workspaceThe workspace file to be loaded. If the file specification does not include a directory, the workspace will be loaded from the configuration directory. If this parameter is not specified, the default workspace (Default.wksp) will be loaded.
-readOnly Puts the connection into read-only mode.

By specifying a simple connection string

ParameterDescription
-connection

Allows to specify a full connection definition as a single parameter (and thus does not require a pre-defined connection profile).

The connection is specified with a comma separated list of key value pairs:

  • username - the username for the connection
  • password - the password for the connection
  • url - the JDBC URL
  • driver - the class name for the JDBC driver. If this is not specified, SQL Workbench/J will try to determine the driver from the JDBC URL
  • driverJar - the full path to the JDBC driver. This not required if a driver for the specified class is already configured

e.g.: "username=foo,password=bar,url=jdbc:postgresql://localhost/mydb"

If an approriate driver is already configured the driver's classname or the JAR file don't have to be specified.

If an approriate driver is not configured, the driver's jar file must be specified:

"username=foo,password=bar,url=jdbc:postgresql://localhost/mydb,driverjar=/etc/drivers/postgresql.jar"

SQL Workbench/J will try to detect the driver's classname automatically (based on the JDBC URL).

If this parameter is specified, -profile is ignored.

The individual parameters controlling the connection behaviour can be used together with -connection, e.g. -autocommit or -fetchSize

In addition to -connection> the following parameters are also supported to specify connections for WbCopy, WbDataDiff or WbSchemaDiff:

  • -sourceConnection
  • -targetConnection
  • -referenceConnection

If a value for one of the parameters contains a dash or a space, you will need to quote the parameter value.

A disadvantage of this method is, that the password is displayed in plain text on the command line. If this is used in a batch file, the password will be stored in plain text in the batch file. If you don't want to expose the password, you can use a connection profile and enable password encryption for connection profiles.