Database connections in Rails project wizard

Recently (6.1 dev, build # >= 516) a new database configuration panel was introduced in the Rails project wizard that lets the user register JDBC connections in the IDE and use existing registered connections. In addition, the wizard now automatically creates a reference to the database driver JAR file(s).

Default behaviour

If the database configuration panel is skipped, by default the project will be generated using the MySQL Rails database adapter, i.e. JDBC will not be used even if the selected platform was JRuby.

Using Rails database adapters

When not using JRuby and/or JDBC, the user can choose to just specify the Rails adapter or select connections registered in the IDE whose connection information will be used to generate database.yml. The behaviour depends on whether which one of the 'Configure Using IDE Connections' and 'Specify Database Information Directly' radio buttons is selected.

When not using connections registered in the IDE, i.e. when the 'Specify Database Information Directly' radio button is selected, the user can choose a Rails database adapter, specify the name of the database and database user credentials. Database.yml will then be generated according to this information. It is important to note that this configuration applies only to the development database - the test and production database configuration are left as they generated by Rails by default - the IDE doesn't alter the configurations for these in any way.

File:RubyDatabaseIntegration/db-no-jdbc RubyDatabaseIntegration.png

Using IDE Connections

An alternative way to configure database is to use the connections registered in the IDE - this can be done by selecting the 'Configure Using IDE Connections' radio button.

It is possible to use the connections registered in the IDE and register new connections both with and without JDBC. All three combo boxes contain an item that lets the user to register a new connection. After the user has specified the connection params, the created connection is registered in the IDE. This means that the connection is visible under the Database node in the Services tab and that the DB explorer can be used for browsing the db structure and performing queries. If there are already some registered connections in the IDE, they will be displayed in the combo boxes.

IDE Connections Without JDBC

If using IDE connections, the IDE will generate database.yml based on the connection parameters of the selected connections. In other words, this means that JDBC connection info will be converted to Rails adapter parameters. For example, if the database URL of the selected connection was jdbc:postgresql://localhost:5432/mydatabase, the respective entry generated to database.yml would be

adapter: postgresql
host: localhost
port: 5432
database: mydatabase
.. ( + user and password)

i.e. no suffixes such as _development are added to the database name. The idea is that it should point to an existing database.

IDE Connections with JDBC

If the 'Access Database Using JDBC' check box is checked, the IDE will configure Rails to use JDBC drivers for accessing database. For example for a MySQL JDBC connection the generated entry in database.yml could look like the following:

      host: localhost
      adapter: jdbc
      driver: com.mysql.jdbc.Driver
      url: jdbc:mysql://localhost:3306/depot_development
      username: user
      password: pwd

File:RubyDatabaseIntegration/db-jdbc RubyDatabaseIntegration.png

Automatic bundling of JDBC drivers

When using JDBC to access the database, the IDE will create references to the driver JAR file(s) of the selected JDBC connections so that the created project is runnable without having to add class path entries to JRuby classpath. The references will be created to and/or, depending on whether the driver files could be referenced using a relative path or an absolute path - if the former, the reference will be in both, and if the latter, the reference will be put only to

Creating MySQL Databases

The Create DB buttons next to the JDBC connection combo boxes let you create MySQL databases. After creating a database, the user is prompted for connection parameters and then the connection to the newly created database is preselected in the corresponding combo box.

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo