Danson Wachira is a certified Trainer in Computer Science, Information Technology and related studies.
Lesson 47: Java NetBeans and Databases
Having covered all the Java Lessons in this tutorial up to this point gives you fundamental knowledge in Java NetBeans programming to work with databases in Java. Creating an interface that actually manipulate datasets according to users’ preference is another level of programming.
With fundamental knowledge that you have acquired through the previous Java lessons, I will now introduce you to Java and databases, how to create databases in Java, how to create tables in Java and how to manipulated data in databases using Java codes.
Applications in Java usually connect to databases using Java Database Connectivity commonly called JDBC. Programs access databases through JDBC API (Application Program Interface) which actually involves programming for database access. The program then use JDBC Driver Manager to connect to the database.
JDBC (Java Database Connectivity) is just a generic database connector and it can be used to connect to a wide-range of databases (Oracle, MySQL, SQL Server etc.)
For the purpose of this tutorial and so that we keep things simple, we’ll use a version of Apache Derby database called Java DB (Database) which is already embedded in Java NetBeans.
Java DB is a virtual server that runs on Java environment where we can activate it (Start) or deactivate it (Stop) depending on program needs.
To start on Java and databases, let us first check if everything we need is available and working correctly. Click on the Services tab located to the left of Projects window.
If you cannot locate the Services tab, click Window on the menu bar and select Services. See the images below.
When you expand on the Databases, more items will be revealed as shown on the image below. Notice the Java DB, Drivers and three databases; databaseERP, employee and sample. The first two databases (databaseERP and employee) are user created, however you should be able to see the sample database as it usually comes with Java NetBeans.
For this lesson, we’ll create a database with one table and connect to it using Java codes and JDBC Driver Manager. A database is a shell with tables having data and their relationships. For the purpose of simplicity, we’ll deal with a single-table-database rather than multi-tables-database.
How to Start Java Virtual Server
To start working with Java and databases we have to set Java Virtual Server up and running, right click on the Java DB and select Start Server.
Clicking Start Server will set up the Java Virtual Server, check on the output window to see if the Apache Derby Network server is ready for connections. If not, check your firewall to make sure it is not blocking the server.
Java Virtual Server Up And Running
If you are with me up to this point, then everything should be working. The Apache Derby Network server is up and running and ready to accept connections. In the next lesson, we shall learn how to create databases and tables in Java NetBeans environment.
Other related Hubs
- Working with user inputs in Java NetBeans
One of the useful classes that handle inputs from a user in Java is the Scanner class. The Scanner class is located in the util (utility) package of the Java library.
- Programming In Java NetBeans - Table Of Contents
Java is increasingly becoming the world’s most popular programming language. This tutorial will take you on step by step Java lessons covering specialized topics on Java programming aimed at providing the fundamental skills needed for beginner..
- Working With Combo Box In Java NetBeans
Java NetBeans provides different Graphical User Interface (GUI) controls to enhance the functioning and user-friendliness of the final application. This article explores different ways of manipulating Java Combo box.
- Working with Arrays of string type in Java NetBeans
In some cases in Java programming, you would need to store values of string type in an array like days of the week or Boolean (True or False) values. In this article, we shall learn how we can implement and work with arrays of string type in Java.
Want to make money online?
nnjiru on October 17, 2013:
Hi Dan Keep the good work your doing. I like this article
Danson Wachira (author) from Nairobi, Kenya on April 22, 2013:
I have to salute you for following, thanks for the visit and comment.
Dianna Mendez on April 21, 2013:
What can I say? Another great article on Java from the expert!