Showing posts with label Oracle. Show all posts
Showing posts with label Oracle. Show all posts

Sunday, January 22, 2012

Example of Java Swing Application with Oracle Database - 2

In the previous blog entry we initiated the construction of a series of articles for constructing a small example application for managing a library, for desktop environment and using Java Swing classes, and accessing an Oracle database.

The previous article addressed the Oracle database creation. This article will handle the construction of a Java class for accessing the database.

We will be using NetBeans IDE 7.0.1, which may be downloaded from http://netbeans.org/community/releases/70/.

After installing NetBeans IDE 7.0.1, we must create a new "Java Class Library" project, which we will name HelperDB, because it will consist only of a single class for helping us access the database.

 
We also create a Java class, that we named DBAccessObj, in file DBAccessObj.java.

It is needed to include two or three (depending on the ORACLE version) JAR library classes to access the Oracle database by using a JDBC driver:


These jar files may be found in directory

                              oraclexe\app\oracle\product\10.2.0\server\jdbc\lib

being oraclexe the directory where Oracle XE has been installed.

Let's now create a package, which we name HelperDB, that will contain our class, and let's import package java.sql, which contains classes for connecting and sending SQL statements to the database:



package HelperDB;

import java.sql.*;

public class DBAccessObj{
       private Connection conn;

       public DBAccessObj()
       {
       }
}


As the only instance variable in our class, we shall create conn of "type" java.sql.Connection.
Actually, Connection is a Java interface, and so conn may contain an object of any type (class) that implements that interface. So, conn may contain an instance of any type of connection. The type will be given by the DriverManager according to the driver that is being used.

The class constructor will then be modified to create a database connection:

Thursday, January 19, 2012

Example of Java Swing Application with Oracle Database - 1

Today we're beginning a series of blog entries that will culminate in a small example Java application for a library management, for desktop environments and using Java Swing classes, and accessing an Oracle database (DB).

This first article addresses the creation of a small Oracle database. It was used Oracle Express 10g, which can be freely downloaded from http://www.oracle.com/technetwork/database/express-edition/downloads/102xewinsoft-090667.html. There is a more recent version of Oracle Express, the 11g release 2, which may be downloaded from http://www.oracle.com/technetwork/database/express-edition/downloads/index.html and with which the example shall also execute correctly.

After installing Oracle, we may access the database administration tool by going to button Start --> All Programs --> Oracle Database 10g Express Edition --> Go to the Database Home Page  or, in a browser, go to http://localhost:8080/apex.

Then, it shall appear a page for us to login in the administration tool:





We shall login with user SYSTEM and the password that we defined for that user during the instalation process.
After logging in the work space appears: