Working with the Java DB (Derby) Database
This document demonstrates how to set up a connection to Java DB database in NetBeans IDE. Once a connection is made, you can begin working with the database in the IDE, allowing you to create tables, populate them with data, run SQL statements and queries, and more.
The Java DB database is Sun's supported distribution of Apache Derby. Java DB is a fully transactional, secure, standards-based database server, written entirely in Java, and fully supports SQL, JDBC API, and Java EE technology. The Java DB database is packaged with the GlassFishapplication server, and is included in JDK 6 as well. For more information on Java DB database, consult the official documentation.
Contents

- Configuring the Database
- Registering the Database in NetBeans IDE
- Starting the Server and Creating a Database
- Connecting to the Database
- Creating Tables
- Adding Table Data
- Deleting Tables
- Using an External SQL Script
- Recreating Tables from a Different Database
- See Also
To follow this tutorial, you need the following software and resources.
Software or Resource | Version Required |
---|---|
NetBeans IDE | 7.2, 7.3, 7.4, 8.0, Java EE |
Java Development Kit (JDK) | Version 7 or 8 |
Java DB | version 10.4.x, 10.5.x |
Note.
- Java DB is installed when you install JDK 7 or JDK 8 (except on Mac OS X). If you are using Mac OS X you can download and installJava DB manually or use the Java DB that is installed by Java EE version of the NetBeans IDE installer.
Configuring the Database
If you have the GlassFish Server registered in your NetBeans IDE installation, Java DB will already be registered for you. Therefore, you can skip ahead to Starting the Server and Creating a Database.
If you downloaded the GlassFish server separately and need help registering it in NetBeans IDE, see Registering a GlassFish Server Instancein the IDE's Help Contents (F1).
If you just downloaded Java DB on its own, perform the following steps.
- Run the self-extracting file. A folder named 'javadb' will be created in the same location as the file. If you just downloaded Java DB and want to have the database server reside in a different location than where it was extracted to, you should relocate it now.
- On your system, create a new directory to be used as a home directory for the individual instances of the database server. For example, you can create this folder in the Java DB root directory (javadb) or in any other location.
Before continuing further, it is important to understand the components found in Java DB's root directory:
- The demo subdirectory contains the demonstration programs.
- The bin subdirectory contains the scripts for executing utilities and setting up the environment.
- The javadoc subdirectory contains the API documentation that was generated from source code comments.
- The docs subdirectory contains the Java DB documentation.
- The lib subdirectory contains the Java DB jar files.
Registering the Database in NetBeans IDE
Now that the database is configured, perform the following steps to register Java DB in the IDE.
- In the Services window, right-click the Java DB Database node and choose Properties to open the Java DB Settings dialog box.
- For the Java DB Installation text field, enter the path to the Java DB root directory (javadb) that you specified in the previous step.
- For Database Location, use the default location if a location is already provided. Click OKFor example, the default location might look like C:\Documents and Settings\username\.netbeans-derby on a Windows machine.Note. If the Database Location field is empty you will need to set the path to the directory that contains your databases. You will need to create a directory for the databases if no directory exists.
Starting the Server and Creating a Database
The Java DB Database menu options are displayed when you right-click the Java DB node in the Services window. This contextual menu items allow you to start and stop the database server, create a new database instance, as well as register database servers in the IDE (as demonstrated in the previous step). To start the database server:
- In the Services window, right-click the Java DB node and choose Start Server. Note the following output in the Output window, indicating that the server has started:
- Right-click the Java DB node and choose Create Database to open the Create Java DB Database dialog.
- Type contact for the Database Name.
- Type nbuser for the User Name and Password. Click OK.Note. The Database Location is the default location set during installation of Java DB from GlassFish. If you installed Java DB separately, this location might be different.
After you create the database, if you expand the Databases node in the Services window you can see that the IDE created a database connection and that the database was added to the list under the Java DB node.