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/Glassfish.
If you install the Sun Java Application Server/GlassFish during the IDE installation,
the Java DB database server is automatically registered in the IDE.
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/Glassfish. 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 Services 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:
- In the Services window, right-click the Java DB node and choose Properties.
- In the dialog box, set the location of the Java DB installation directory.
- Set the folder where your Java DB databases are stored in the Database Location property.
- Click OK.
- In the Services window, Right-click the Java DB node and choose Start Server.
Once your Java DB database is registered with the IDE,
the Java DB Database menu item appears under the Databases Node in the Services 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:
- In the Services window, right-click the Java DB node and choose Create Database.
- In the Create Java DB Database dialog box, 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.
To change the default location, click Properties in the Create Java DB Database dialog box, or in the Services window, right-click the Java DB node and choose Properties. Type the new database location in the appropriate field.
To connect to an existing Java DB database:
- In the Services 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.
- Network 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 Java EE 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 Services 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 default location for the sample database is in the .netbeans-derby directory in your home directory.
- To change the default location for the Java DB database directory, in the Services winow, right-click the Java DB node in the Services window and choose Properties. Enter the new location.
- The Java DB database server replaces the PointBase database server bundled with previous versions of the Sun Java System Application Server.
- See Also
- Connecting to a Database
Legal Notices