Friday, April 11, 2014

Working with Java DB in NetBeans

Java DB is part of the java JDK from version later than 5. To use Java DB in the NetBeans IDE, follow the steps below.

A. Create a Java DB Database in NetBeans


  1. Click Window on the top menu and choose Services. 
  2. In Services window, expand the Database node, 
  3. Right click on Java DB and choose Properties to view the installation and location of the database
  4. Right click on Java DB and choose Start Server
  5. Right click on Java DB again and choose Create Database. Enter the Database Name, User Name and Password, and click OK.


Now the database is ready to use.
Driver: org.apache.derby.jdbc.EmbeddedDriver
URL: jdbc:derby:<database name>

B. Make connection to database


  1. Expand the Java DB node
  2. Right click on you database name and choose connect
  3. A connection node with the text "jdbc:derby://localhost:1527/<database name> [<username> on <username in upper case>]" appears under the Drivers


C. Create table, view, and execute query


  1. Expand the connection node created in B
  2. Expand the node whose text corresponds to your schema


    3. Use the Create Dialog
        1). To create a table, right click on the Tables node and choose Create Table. In the pop up window, enter your table name, and use the Add column button to add columns, then click OK.
        2). To create a view, right click on the Views node and choose Create View. In the pop up window, enter your view name and the SQL to created the view, then click OK.

     4. Use the SQL Editor
         1). Right click on the connection node, or the Tables node, or the Views node, or a table node, choose Execute Command.
         2). In the SQL editor appeared in the main pane of the NetBeans, enter your SQL statement
         3). Highlight the SQL you want to execute and click the Run SQL button (Ctrl+Shift+E)  on top of the SQL editor to execute

If you would like to know how to communicate with your Java DB database through your java code, please read my post Java DB, the Oracle open source database for sample code.

References:

1. Java DB, the Oracle open source database
2. Working with the Java DB (Derby) Database

--------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.


No comments:

Post a Comment