Connecting to a Derby Database
See Also
The Apache Derby Project provides an open source database server that is written
fully in the Java programming language. Starting with version 8.2, the Sun Java
System Application Server bundles the Derby database server instead of the PointBase
database server.
To enable the Derby database server in the IDE, do one of the following:
- Register
an instance of the Sun Java System Application Server 8.2. This registers
the installation of the Derby database server that is packaged with the application
server. The connection to the sample Derby database is automatically displayed
in the Runtime window. The default user name and password for the sample database
is app.
- Register an existing Derby installation. If you already have the Derby database
server installed on your computer, you can register the database with the
IDE by doing the following:
- Choose Tools > Options from the main window.
- Click Advanced Options in the Options window.
- In the left pane of the Options window, expand IDE Configuration >
Server and External Tool Settings > Derby Options.
- Set the location of the Derby JAR files in the Derby Location property.
- Set the folder where your Derby databases are stored in the Database
Location property.
- Click Close.
Once you have installed the Derby module or registered an instance of version
8.2 of the application server, the Derby Database menu item appears under Tools in the main window.
To create a new Derby database:
- Choose Tools > Derby Database > Create Derby Database from the main
window.
- Enter a name for the database, a user name, and a password.
The IDE creates the database in the .netbeans-derby folder of your
home directory.
To connect to a Derby database:
- In the Runtime window, expand Databases > Drivers.
- Right-click the appropriate Apache Derby driver node and choose Connect
Using. Choose one of the following drivers:
- Embedded Driver. Use this driver when you are sure your application will access
the database from a single JVM. A typical example of this scenario is a single-user
Swing JDBC application using a Derby database as a data store.
- Net Driver. Use this driver when you need to connect to the database
from multiple JVMs. An example of this scenario is when you need to connect
from the IDE and from a J2EE application on the application server. Using
the net driver, you can also access the database from remote computers.
- Enter the URL of the database. The URL format is given in the textbox:
jdbc:derby://<HOST>[:<PORT>]/<DB>
- If the database you are connecting to is in the default Derby database
folder, you only have to specify the database name. If the database is
not in the default database folder, you have to enter the full path to
the database and not just the database name.
- Enter a user name and password.
- Click OK. The IDE displays the connection to the database under the Databases
node in the Runtime window.
Notes:
- Selecting Remember Password will store the password for the current IDE
session. If left unselected, a dialog box appears prompting you for the password
every time you connect to the database.
- The URL for the sample database is jdbc:derby://localhost:1527/sample.
The sample database is located in the .derby-netbeans directory
- If you download and install a bundle of the IDE and Sun Java Application
Server 8.2, the Derby database server is automatically registered in the IDE.
- You can change the default Derby database folder in the Derby Database settings
node of the Options window's Advanced Options mode.
- See Also
- Connecting to a Database
Legal Notices