IntelliJ IDEA 14.1.0 Help

Working with Database Consoles

Database consoles let you compose and execute SQL statements for databases defined in IntelliJ IDEA as data sources. They also let you analyze and modify the retrieved data.

The following standardized and DBMS vendor-specific SQL dialects are supported: DB2, Derby, H2, HSQLDB, MySQL, Oracle, Oracle SQL*Plus, PostgreSQL, SQL Server, SQL92, SQLite, and Sybase .

One database console is created for a data source automatically when a data source is created. If necessary, you can create additional consoles.

Database consoles are persistent: they are stored as SQL files.

A database console created in one of your projects can then be accessed from any other project.

General console usage instructions are on this page:

More specific subjects are discussed in:

See also, Database Console.

Creating a database console

When you create a DB data source, one database console for that data source is created automatically. If necessary, you can create additional consoles.

To create a database console, you can use the Database tool window or the Scratches view of the Project tool window. The procedure is the same in both cases:

Select the data source of interest or any node within it, and do one of the following:

  • Select File | New | Console from the main menu.
  • Select New | Console from the context menu
  • Press Alt+Insert and select Console.

In the Database tool window, you can also use the toolbar: click add and select Console.

Opening a database console

The Database tool window lets you open only default consoles, i.e. the ones that were created by IntelliJ IDEA automatically.

To open the consoles that you created yourself, you should use the Scratches view of the Project tool window.

Using the Database tool window. Select the data source of interest or any node within and do one of the following:

  • Click ConsoleOnTitleBar on the title bar if the toolbar is hidden.
  • Click runJdbcConsole on the toolbar if the toolbar is shown.
  • Select Console from the context menu.
  • Press Ctrl+Shift+F10.

Using the Scratches view. For the console of interest, do one of the following:

  • Double-click the console.
  • Select View | Jump to Source from the main menu.
  • Select Jump to Source from the context menu.
  • Press F4.

Viewing and modifying console settings

Before actually starting to use a console, you may want to take a look at the console settings and adjust them to your needs.

  • To access these settings, click settings on the toolbar of the input pane or on the toolbar of the Database Console tool window. (Alternatively, Ctrl+Alt+S | Tools | Database.)

As a result, the Database page of the Settings dialog opens. On this page, you can, for example, specify:

  • How query results should be shown (the Data View and the Console sections).
  • Which characters and their sequences should be treated as SQL parameters and in which places (the Custom SQL parameters section).
  • How retrieved table data should be converted into CSV, TSV and other formats (the Data Extractors section).

Changing the SQL dialect

By default, the SQL dialect used in a console is defined by the DBMS of an associated data source. If for some reason you want to use a different dialect:

  1. Right-click in the editing area of the input pane to open the context menu.
  2. Point to Change '<current_dialect_name>' dialect to and select the necessary dialect.

    In addition to particular dialects, also the following option is available:

    • <Generic>. Basic SQL92-based support is provided including completion and highlighting for SQL keywords, and table and column names. Syntax error highlighting is not available. So all the statements in the input pane are always shown as syntactically correct.

Closing a console

To close a console, do one of the following:

  • Click close on the toolbar of the Dababase Console tool window.
  • Press Ctrl+Shift+F4.

Managing database consoles

To manage your database consoles, use the Scratches view of the Project tool window.

To open this view, select Scratches from the list in the left-hand part of the title bar.

projectToolWindowViews

The view shows the existing database consoles (represented by SQL files) grouped by your data sources (shown as folders). The default consoles (the ones that were created by IntelliJ IDEA automatically) have the same names as the corresponding data sources.

projectToolWindowScratchesViewDBE

You can:

  • Create new consoles. Select the target data source or a node within it, and do one of the following:
    • Select File | New | Console from the main menu.
    • Select New | Console from the context menu
    • Press Alt+Insert and select Console.
  • Rename your consoles. When a new console is created, it has the name of the data source with a number at the end, e.g. MySQL_1. If you want to give a console a more descriptive name, select the console and do one of the following:
    • Select Refactor | Rename from the main or the context menu.
    • Press Shift+F6.

    Then, specify a new name in the dialog that opens.

  • Group your consoles. This is done by creating folders and then dragging your consoles into those folders.
  • Open your consoles. Select the consoles of interest and do one of the following:
    • Select View | Jump to Source from the main menu.
    • Select Jump to Source from the context menu.
    • Press F4.
  • View the history of changes for your consoles. Select File | Local History | Show History from the main menu or Local History | Show History from the context menu.
  • Delete individual consoles and groups of consoles. Use Edit | Delete, Delete from the context menu or Delete on the keyboard.

See Also

Last modified: 14 July 2015