How To Use Apache Derby In NetBeans
Apache Derby in NetBeans
In JDBC, NetBeans provides support to create and maintain the relational databases by embedding the Apache Derby DBMS in the IDE.
Apache Derby
- It is an open source relational database.
- It is implemented entirely in Java.
- It has a small footprint, near about 2 megabytes for the base engine and JDBC driver.
- It is based on Java, JDBC and SQL standards.
- It can be run in embedded or network mode.
- It is bundled with NetBeans.
Java DB Server
Apache Derby is called as a "Java DB" in NetBeans.
To manage Java DB, it exposes the Services tab in the upper left Window of IDE and open the databases node.
Start the Java DB Server
We should see Java DB in the databases tree, right click Java DB to start and stop the database server.
Java DB Process Output Window
When Java DB Server is running, we should see a tab labeled Java DB Database Process at the bottom of the IDE in the output area, given below.
A Sample Database
NetBeans packages a sample database with IDE.
Under the databases tree, look for jdbc:derby://localhost:1527/sample, right-click the sample database and select connect, as given below.
List the Sample Database Tables
A database connection will be created and a node labeled CONTACT will appear under the database node in the tree.
Open the CONTACT node to reveal folders for Tables, Views and Procedures.
Open the Tables folder to expose some tables for a business Application, given below.
List Columns
We can see a table's columns by opening a table node.
Here is the result of opening the CUSTOMER table, given below.
List Column Properties
If we right click a table column node and choose Properties, as given below.
We can view the column constraints, as given below.
View Table Data
We can view the contents of a table by right clicking the table node and choosing View Data, as given below.
SQL Command Window
Requesting to view a table's data produces a SQL Command Window.
A select statement is produced, placed in the command Window and then executed.
The result is displayed in the bottom of the Window, as given below.
Creating a New Database
If we want to create a new database, right click Java DB node and select Create database.
Creating the Bike Database
To create a new, empty, database, give a database name, user name and password.
To create the database.
While the choice of user name is up to us, "app" is appropriate since the database is to be used by a web application. Be sure to memorize the database name, user name, and password, as they are required in order to create a data source.
Connecting to the Bike Database
To connect.
Now, if we want to add some own database, we can add and use easily.
Summary
Thus, we learnt, In JDBC, NetBeans provides support to create and maintain the relational databases by embedding Apache Derby DBMS in the IDE and also learn how we can create a database.