IntelliJ IDEA does not enable you to create databases, but provides facilities to manage and query them. Once you are granted access to a certain database, you can configure one or more data sources within IntelliJ IDEA that reflect the structure of the database and store the database access credentials. Based on this information, IntelliJ IDEA establishes connection to the database and provides the ability to retrieve or change information contained therein.
In this section:
Data source scopes
There are the data sources that are available in all of your projects. Such data sources are said to have the IDE scope. Others, ones with the project scope, are available in only one of your projects.
Data source types
IntelliJ IDEA supports data sources of the following types:
- DB data sources (also called database connections), which correspond to real databases.
- DDL data sources, which represent the necessary data structures and act as stub databases, the databases without any data. For this data source type you should have one or more SQL DDL files representing the required data structures available in your project directory (or one of its subdirectories). Also note that a particular SQL dialect should be set for all those files (or the directories containing those files).
DB data sources can have the IDE or the project scope; DDL data sources exist only at the project level.
Similarly, all database connections are automatically terminated when you exit the IDE.
The database connection status is shown in the Database tool window at the level of the data source nodes. The data sources with open connections have the text [connected] to the right of their names.
If necessary, you can close all unnecessary database connections manually. To do that:
- In the Database tool window, select the corresponding data source or data sources. (To select more than one data source, use mouse clicks in combination with the Ctrl key.)
Do one of the following:
- Click on the toolbar.
- Select Disconnect from the context menu.
Overview of the features
Here is a very brief overview of IntelliJ IDEA features related to working with data sources:
- Support for SQL, which includes syntax and error highlighting, code completion, selection of words and statements, parameter lookup, and refactoring (Introduce constant, for instance).
- The ability to use source files with injected SQL code, with different SQL dialects, configurable at the project, directory, or file level.
- Dedicated Database tool window, where you can configure data sources.
- Dedicated Database, Hibernate, and JPA consoles.
- Configuring DDL data sources based on data structure definition (DDL) files, integration between the data source structure and the corresponding DDL statements in the definition file.
- Generating DDL statements based on the structures of a data source.
- Configuring database management scripts as external tools and running them from within IntelliJ IDEA.
- The ability to download archives and libraries with driver classes right from IntelliJ IDEA.
- Object-relational mapping by means of EJB, Hibernate and JPA.
- Persistence tool window that enables mappings between relational databases and object models.
- Table Editor that provides a graphical interface for viewing and editing database tables.
- Structure view for DDL SQL files available in the Structure tool window ( or Alt+7Alt+7Alt+7Alt+7Alt+7Alt+7 or Ctrl+Alt+SAlt+7Ctrl+7 or Alt+7Alt+7Command 7Command 7Command 7) or in the Structure pop-up ( or Ctrl+F12Ctrl+F12Ctrl+0Ctrl+F12Ctrl+F12Ctrl+F12Ctrl+F12Ctrl+F12 or Ctrl+Shift+F12Ctrl+F3 or Ctrl+OCommand F12Command F12Command O).