Connecting to a Java DB Database
See Also
The Java DB database is Sun's supported distribution of the open source Apache Derby database.
Java DB is a fully transactional, secure, standards-based database server, written
fully in the Java programming language, and fully supports SQL, JDBC API, and Java EE technology.
The Java DB database server is bundled with the Sun Java System Application Server 9.0, Platform Edition.
The Java DB database server replaces the PointBase database server bundled with previous versions of the Sun Java System Application Server.
To enable the Java DB database server in the IDE, do one of the following:
- Register
an instance of the Sun Java System Application Server 9.0, Platform Edition. This registers
the installation of the Java DB database server that is packaged with the application
server. The connection to the sample Java DB database is automatically displayed
in the Runtime window. The default user name and password for the sample database
is app.
- Register an existing Java DB or Apache Derby installation.
If you already have one of these database servers 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 > Java DB Database.
- Set the location of the Java DB installation directory in the Java DB Location property.
- Set the folder where your Java DB databases are stored in the Database Location property.
- Click Close.
Once your Java DB database is registered with the IDE,
the Java DB Database menu item appears under Tools in the main window.
This menu item enables you to easily start and stop the Java DB database server, and to create a new database.
To create a new Java DB database:
- Choose Tools > Java DB Database > Create Java DB Database from the main window.
- Enter a name for the database, a user name, and a password.
By default, the IDE creates the database in the .netbeans-derby folder of your home directory.
You can change the default location by choosing Tools > Options > Advanced Options > IDE Configuration >
Server and External Tool Settings > Java DB Database > Database Location property.
To connect to an existing Java DB database:
- In the Runtime window, right-click the Databases node and choose New Connection.
- In the New Database Connection dialog box, choose one of the following Java DB drivers from the drop-down menu:
- 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 Java DB 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 Java DB 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 .netbeans-derby directory in your home directory.
- If you download and install a bundle of the IDE and Sun Java Application
Server 9.0, Platform Edition, the Java DB database server is automatically registered in the IDE.
- You can change the default Java DB database folder in the Java DB Database settings
node located under IDE Configuration in the Advanced Options view of the Options window.
- See Also
- Connecting to a Database
Legal Notices