Connecting to a database
To be able to work with your database, define it as a data source. This page provides how tos for popular database management systems and typical situations.
PostgreSQL
- Open the Database tool window (e.g. ) and click
to open the Data Sources and Drivers dialog.
- Click
and select PostgreSQL.
- In the lower part of the dialog, within Download missing driver files, click the Download link.
- Specify the database connection settings and your user account info:
- Host. If you database server is on a different computer, replace
localhost
with the FQDN or IP address of the server host, e.g.mydbserver.example.com
or172.20.240.163
. - Port. The default PostgreSQL server port is
5432
. If your server uses a different port, specify that port. - Database. The name of the database that you are going to work with.
- User and Password. These are your database user name and password.
- Host. If you database server is on a different computer, replace
- If necessary, edit the data source name.
- To connect via SSH, specify the SSH proxy settings.
- To make sure that the settings are OK, click Test Connection.
Click OK.
Now, as a final check, execute a couple of queries.
- If necessary, form the schema search path using the popup in the upper-right part of the console. For instructions, see Controlling the schema search path for PostgreSQL and Redshift.
- Type your query, e.g.
CREATE TABLE mytesttable ( myfield INT );
- Execute the query:
or Ctrl+Enter.
- If necessary, execute another query, e.g.
DROP TABLE mytesttable
PostgreSQL on Heroku
- Open the Database tool window (e.g. ) and click
to open the Data Sources and Drivers dialog.
- Click
and select PostgreSQL.
- In the lower part of the dialog, within Download missing driver files, click the Download link.
- Select the Advanced tab and specify the following properties:
- ssl:
true
- sslfactory:
org.postgresql.ssl.NonValidatingFactory
These will turn SSL on and the certificate validation off.
- ssl:
- Click Apply and select the General tab.
- Go to your Heroku dashboard and display your database settings: e.g. click your app, under Installed add-ons, click Heroku Postgres, and then, in the ADMINISTRATION section, click View Credentials.
- Copy the settings from the dashboard onto the General tab.
- If necessary, edit the data source name.
- To make sure that the settings are OK, click Test Connection.
Click OK.
Now, as a final check, execute a couple of queries.
- If necessary, form the schema search path using the popup in the upper-right part of the console. For instructions, see Controlling the schema search path for PostgreSQL and Redshift.
- Type your query, e.g.
CREATE TABLE mytesttable ( myfield INT );
- Execute the query:
or Ctrl+Enter.
- If necessary, execute another query, e.g.
DROP TABLE mytesttable
Microsoft SQL Server
- Open the Database tool window (e.g. ) and click
to open the Data Sources and Drivers dialog.
- Click
and select SQL Server (jTds) or SQL Server (Microsoft). These options differ only in the database driver that is used: jTDS or Microsoft.
- In the lower part of the dialog, within Download missing driver files, click the Download link.
- Specify the database connection settings and authentication options:
- Host. If you database server is on a different computer, replace
localhost
with the FQDN or IP address of the server host, e.g.mydbserver.example.com
or172.20.240.163
. - Port. Specify the server port; the default port for SQL Server is
1433
. - Instance. If you are connecting to a default server instance, don't specify anything. Otherwise, specify the instance name.
- Database. Specify the name of the database that you are going to work with.
- Use Windows domain authentication. To use Windows Authentication, leave the check box selected. To use SQL Server Authentication, clear the check box, and specify your user name and password.
- Host. If you database server is on a different computer, replace
- If necessary, edit the data source name.
- To connect via SSH, specify the SSH proxy settings.
- To make sure that the settings are OK, click Test Connection.
Click OK.
Now, as a final check, execute a couple of queries.
- Type your query, e.g.
CREATE TABLE mytesttable ( myfield INT );
- Execute the query:
or Ctrl+Enter.
- If necessary, execute another query, e.g.
DROP TABLE mytesttable
Microsoft Azure
- Open the Database tool window (e.g. ) and click
to open the Data Sources and Drivers dialog.
- Click
and select Azure (Microsoft).
- In the lower part of the dialog, within Download missing driver files, click the Download link.
- Specify the database connection settings and authentication options:
- Host. This is the FQDN of your server. Within the default
server.database.windows.net
you, most likely, only need to replace theserver
part with the name of your server. - Port. The default Azure server port is
1433
. - Database. The name of the database that you are going to work with.
- Use Windows domain authentication. To use Azure Active Directory Authentication, leave the check box selected. To use SQL Authentication, clear the check box, and specify your user name and password.
- Host. This is the FQDN of your server. Within the default
- If necessary, edit the data source name.
- To connect via SSH, specify the SSH proxy settings.
- To make sure that the settings are OK, click Test Connection.
Click OK.
Now, as a final check, execute a couple of queries.
- Type your query, e.g.
CREATE TABLE mytesttable ( myfield INT );
- Execute the query:
or Ctrl+Enter.
- If necessary, execute another query, e.g.
DROP TABLE mytesttable
MySQL
- Open the Database tool window (e.g. ) and click
to open the Data Sources and Drivers dialog.
- Click
and select MySQL.
- In the lower part of the dialog, within Download missing driver files, click the Download link.
- Specify the database connection settings and your user account info:
- Host. If you database server is on a different computer, replace
localhost
with the FQDN or IP address of the server host, e.g.mydbserver.example.com
or172.20.240.163
. - Port. The default MySQL server port is
3306
. If your server uses a different port, specify that port. - User and Password. These are your database user name and password.
- Host. If you database server is on a different computer, replace
- If necessary, edit the data source name.
- To connect via SSH, specify the SSH proxy settings.
- To make sure that the settings are OK, click Test Connection.
Click OK.
Now, as a final check, execute a couple of queries.
- Select your default schema from the list in the upper-right part of the console.
- Type your query, e.g.
CREATE TABLE mytesttable ( myfield INT );
- Execute the query:
or Ctrl+Enter.
- If necessary, execute another query, e.g.
DROP TABLE mytesttable
Oracle
- Open the Database tool window (e.g. ) and click
to open the Data Sources and Drivers dialog.
- Click
and select Oracle.
- In the lower part of the dialog, within Download missing driver files, click the Download link.
- Specify the database connection settings and your user account info:
From the list to the right of URL, select SID or Service Name, or TNS.
- If SID or Service Name is selected, the settings are:
- Host. If you database server is on a different computer, replace
localhost
with the FQDN or IP address of the server host, e.g.mydbserver.example.com
or172.20.240.163
. - Port. The default Oracle server port is
1521
. If your server uses a different port, specify that port. - SID or Service. The Oracle system ID or service name for your database. The typical values are
XE
orORCL
.To find out what the value should be, check the environment variable
ORACLE_SID
on the server host, or contact your database administrator.
- Host. If you database server is on a different computer, replace
- If TNS is selected, the connection settings are read from a tnsnames.ora configuration file. So you should specify:
- TNSADMIN. The path to the directory in which your
tnsnames.ora
file is located. - TNS name. If in your
tnsnames.ora
file, there is more than onenet_service_name
, specify the one that should be used.
- TNSADMIN. The path to the directory in which your
The rest of the settings are:
- Driver. The default Thin driver will do in most of the cases. For more info, see Oracle JDBC FAQ.
- User and Password. These are your database user name and password.
- If SID or Service Name is selected, the settings are:
- If necessary, edit the data source name.
- To connect via SSH, specify the SSH proxy settings.
- To make sure that the settings are OK, click Test Connection.
Click OK.
Now, as a final check, execute a couple of queries.
- Type your query, e.g.
CREATE TABLE MYTESTTABLE ( MYFIELD INT );
- Execute the query:
or Ctrl+Enter.
- If necessary, execute another query, e.g.
DROP TABLE MYTESTTABLE
Amazon Redshift
- Open the Database tool window (e.g. ) and click
to open the Data Sources and Drivers dialog.
- Click
and select Amazon Redshift.
- In the lower part of the dialog, within Download missing driver files, click the Download link.
- To the right of the URL field, select URL only.
- Go to your Redshift Dashboard, select Clusters, select the cluster you want to connect to, and copy the JDBC URL listed under Cluster Database Properties onto the clipboard.
- Paste the URL into the URL field.
- Specify your user name and password.
- If necessary, edit the data source name.
- To connect via SSH, specify the SSH proxy settings.
- To make sure that the settings are OK, click Test Connection.
Click OK.
Now, as a final check, execute a couple of queries.
- If necessary, form the schema search path using the popup in the upper-right part of the console. For instructions, see Controlling the schema search path for PostgreSQL and Redshift.
- Type your query, e.g.
CREATE TABLE mytesttable ( myfield INT );
- Execute the query:
or Ctrl+Enter.
- If necessary, execute another query, e.g.
DROP TABLE mytesttable
SQLite
- Open the Database tool window (e.g. ) and click
to open the Data Sources and Drivers dialog.
- Click
and select Sqlite.
- In the lower part of the dialog, within Download missing driver files, click the Download link.
- To create a new database, specify its name in the File field (e.g.
mynewdb.sqlite
) and click.
To use an existing database, click
and select the database file in the dialog that opens.
- To make sure that the settings are OK, click Test Connection.
Click OK.
Now, as a final check, execute a couple of queries.
- Type your query, e.g.
CREATE TABLE mytesttable ( myfield PRIMARY KEY );
- Execute the query:
or Ctrl+Enter.
- If necessary, execute another query, e.g.
DROP TABLE mytesttable
Vertica as an example of 'unsupported' DBMS
An "unsupported" DBMS is one that is not present in the list of database management systems, when you click in the Data Sources and Drivers dialog. You can still connect to such a database if there is a JDBC driver for it.
In this section, we provide corresponding how-to instructions using Vertica as an example.
- Download a JDBC driver for the DBMS that you are going to connect to. A driver, usually, is one or more
.jar
files. - Open the Database tool window (e.g. ) and click
to open the Data Sources and Drivers dialog.
- Click
and select Driver and Data Source.
Your data source settings, initially, look something like this:
- To the right of Driver, click the Database Driver link.
Now we are going to specify the driver.
- In the JDBC drivers section, click
and select your driver file or files in the dialog that opens.
- Specify:
- Name. Change the default name, for example, to the name of your DBMS.
- Class. Usually, this is something like
com.<company_name>.jdbc.Driver
e.g.
com.vertica.jdbc.Driver
- Dialect. Select the dialect which is the closest to your DBMS SQL dialect.
- Click Apply, and select your data source under Project Data Sources.
- Specify:
- URL. Your database connection URL. For corresponding info, refer to your DBMS documentation. Usually, this is something like
jdbc:<dbms_name>://<host>:<port>/<db_name>
e.g.
jdbc:vertica://localhost:5433/docker
- User and Password. These are your database user name and password.
If necessary, edit the data source name.
- URL. Your database connection URL. For corresponding info, refer to your DBMS documentation. Usually, this is something like
- To connect via SSH, specify the SSH proxy settings.
- To make sure that the settings are OK, click Test Connection.
Click OK.
Now, as a final check, execute a couple of queries.
- Type your query, e.g.
CREATE SCHEMA myschema;
- Execute the query:
or Ctrl+Enter.
- If necessary, execute another query, e.g.
DROP SCHEMA myschema
Connecting via SSH
To access your database via SSH, specify the settings for your SSH proxy server on the SSH/SSL tab.
- Select the Use SSH tunnel check box.
- Specify the settings:
- Proxy host.
localhost
if the server is on the same computer. Otherwise, the FQDN or IP address of the server host, e.g.mysshproxy.example.com
or172.20.241.34
. The server host must be accessible by the specified name or IP address from your local computer. - Port. The SSH port; the default port is
22
. - Proxy user. Your SSH server user name.
- Auth type. The authentication type used by your server:
- Password. Password-based authentication. If this authentication type is used, you should specify your password.
- Key pair (OpenSSH). Key-based authentication. If this authentication type is used, you should specify:
- The location of your private key file.
- The passphrase for the private key - if the key is locked with the passphrase.
- Proxy host.
- To make sure that the settings - ones for the database and the proxy server - are all OK, click Test Connection.