JavaDB



JavaDB

Randy Robertson

Special Interest Activity

ITK 478

Dr. Lim

TABLE OF CONTENTS

Introduction 2

Research 3

Hands On Documentation 6

Application Code 7

Reflective Summary 15

Summary of Weekly Activities 16

Conclusion 17

References 18

Introduction

This project involves the fundamental aspects of JavaDB, a database written in Java that will be included in the Java 6 release by Sun Microsystems. The first part documents the history and basic information relating to JavaDB. I also compare it to other databases (fully featured and embedded). Then the hands on approach I used is documented. I created a sample database in JavaDB and used screenshots to show the results. Finally, I describe my previous and current knowledge embedded databases and how it relates to JavaDB. I hope you find the information contained in the paper useful to draw an opinion on the JavaDB application.

Research

Introduction

JavaDB is a fully functional embedded database created entirely in Java. It will be included in the next Java release (JDK 6), which will be released soon (Taft, 2006). This paper will detail some of the history, as well as benefits of JavaDB. Finally, we will discuss the similarities and differences to another embedded database, BerkleyDB.

History

The source code for JavaDB has been around for nearly 10 years. The original database, eventually called Cloudscape, was released in 1997. In 1999, Informix purchased Cloudscape, and, in 2001, Informix was purchased by IBM. IBM eventually decided to donate the Cloudscape source code to the Apache Software Foundation. Apache renamed the project Apache Derby. (Brunner, 2006) Late in 2005, Sun announced that it would release its own version of Derby called JavaDB. So the same embedded database can be called by three names: Cloudscape, Derby or JavaDB. The additional names are needed because IBM and Sun can support and maintain the JavaDB databases for organizations. This paper will refer to the database as JavaDB.

Elements of JavaDB

JavaDB gives developers flexibility in terms of deployment. Developers can use JavaDB as either an embedded database or as a client server database. To use JavaDB with an application, a developer can deploy a copy of JavaDB along with the application and it would then store all of the information locally on the host computer. One such example would be a application that stores customers addresses. JavaDB can handle multiple connections from other hosts. So data that would be useful to many hosts can be accessed from a JavaDB database stored on a server. Many organizations use databases in this way, as data is frequently shared. (Brunner, 2006)

One of the main benefits of JavaDB is that its size, or “footprint”, is only 2MB. The reason for this is because the main JavaDB files are saved in the jar file format. A jar file is a compressed file based on the zip file format. Jar files can be run directly by the Java Virtual Machine without the need for decompression. A jar file is more secure because the file can be digitally signed at the time of compression, which would prevent unauthorized access. (Suresh, 2003)

When used as an embedded database, JavaDB is stored in a folder on the host machine. Within that folder are several files. A log directory stores a database transaction log, which is used for data recovery. A Seg0directiry file is comprised of user and system tables along with any indexes (One file per table or index). The service.properties file contains database configuration information. The database might also contain tmp (Used for temporary storage of sorts and delayed updates and deletes) and jar files. (Derby Developer’s Guide, 2006)

JavaDB does not impose many limitations on the databases it uses. JavaDB limits the total number of columns to 1012 and 16 columns are allowed per index. However, most other properties, such as number and size of tables and rows, have no database imposed limit. Some operating systems might impose a limit on the file sizes, which might limit larger database tables. (Derby Developer’s Guide, 2006)

Application developers can create applications using JavaDB along with IDEs such as Eclipse, Java Studio Creator, and Netbeans. However, JavaDB has a few tools that can be used with the command interface. The most important tool is called ij, which is the JDBC scripting tool. Ij can be used to write SQL statements and test code with non SQL commands. Another feature of JavaDB is that data stored in a text file can be imported and exported using SQL statements. One limitation of JavaDB is that XML data cannot be imported or exported. This is a major disadvantage of other RDMBS such as Oracle. (Derby Tools and Utilities, 2006)

Security is an important factor when using a JavaDB application. JavaDB is able to provide a few different forms of protecting the data in the files. The following security features are supported: User Authentication and Authorization, Disk Encryption, and Certificate Validation of Signed Jar Files. User authentication prevents unauthorized access to JavaDB. Without a valid username and password, the user will not be able to use the application. The authentication default setting is disabled so the developer will need to activate this feature when coding the application. User Authorization can limit users from having full read/write access or prevent users from using certain SQL commands. This security feature can be enabled at the system level or at the database level. This allows flexibility in a client-server connection where many users might access the same database. Disk encryption is important when using JavaDB. Typically, data is only encrypted over a connection and decrypted once received at the client. There is no way to ensure that the data on the client computer is secure, since one of the benefits of JavaDB is that files can be easily shared among different computers. So JavaDB can store files encrypted on the disk both at the server and client side. JavaDB also has the ability to verify that a jar file was signed with an X.509 certificate. The X.509 certificate will alert the user if the file has been tampered with. (Derby Developer’s Guide, 2006)

Comparisons

As stated earlier, JavaDB is a fully functional relational database. Oracle and DB2 are more complex versions of relational databases when compared to JavaDB. JavaDB supports SQL92 standards and many of the SQL99 extensions as well. (Saunders 2006). Oracle and DB2 can be complex to learn and administer. Small business owners could not take time to learn all of the functions of Oracle. The Documentation Library on Oracle’s website is extremely technical. JavaDB allows an option of a fully functional database that implements all of the common SQL standards, and does it in a simple fashion. The article by Saunders (2006) lists all of the SQL implementations in JavaDB The article references the Cloudscape application, but, as I stated earlier, it is the same product.

Oracle recently purchased a company called Sleepycat Software, which created an embedded database called BerkeleyDB (). When comparing BerkeleyDB and JavaDB, the clear choice is JavaDB. First, BerkeleyDB is not a relational database. (Oracle Data Sheet, 2006) It stores data in the same format as the application. While this does reduce processing time, if the data needed to be converted into a larger product, such as Oracle or DB2, then that process would be difficult if not impossible. Another drawback regarding BerkeleyDB is the dual license. If an organization creates an application that uses BerkeleyDB and intends to release it commercially, it would need to purchase a commercial license from Oracle. There is also an open source license allowing developers to create an application using BerkeleyDB as long as they release the source code of the program. (Oracle Data Sheet, 2006) JavaDB is based on the Apache license, which allows a developer to commercially distribute an application containing JavaDB, which is similar to what Sun is doing by offering support for JavaDB.

Hands On Documentation

To show the basic functionality of JavaDB, I’ve created 3 Java applications that will interact with JavaDB. The sample database will be called Name and it will consist of the following attributes:

Name(First_Name, Last_Name, Phone_Number)

The first step is to run the sysinfo tool using the command line to set the classpaths

[pic]

The sysinfo tool lists the classpaths and other assorted information related to JavaDB. All of my files will be saved in the C:\Documents and Settings\Randy folder

The Name table will be stored in a database entitled lim478

The code uses the url : jdbc:derby:lim478;create=true

The create=true statement creates the database if it does not already exist.

Here is the application code to access the database.

Application Code

The JavaDBNames application will create the table Name. Here is the application code for the JavaDBNames File.

import java.sql.*;

import java.util.*;

public class JavaDBNames {

public static void main(String args[]) {

String url = "jdbc:derby:lim478;create=true";

Connection con;

String createName;

createName = "create table NAME " +

"(F_Name varchar(20), " +

"L_Name varchar(20), phoneNum varchar(15))";

Statement stmt;

try {

Class.forName("org.apache.derby.jdbc.EmbeddedDriver");

} catch(java.lang.ClassNotFoundException e) {

System.err.print("ClassNotFoundException: ");

System.err.println(e.getMessage());

}

try {

con = DriverManager.getConnection(url);

stmt = con.createStatement();

stmt.executeUpdate(createName);

System.out.println("The Table Name has been created");

stmt.close();

con.close();

} catch(SQLException ex) {

System.err.println("SQLException: " + ex.getMessage());

}

}

}

The JavaDBInsertNames application is a way for the user to enter information to be saved in the JavaDB database. Here is the application code for the JavaDBInsertNames File.

import java.sql.*;

import java.util.*;

public class JavaDBInsertNames {

public static void main(String args[]) {

String url = "jdbc:derby:lim478;create=true";

Connection con;

Statement stmt;

String query = "select F_Name, L_Name, phoneNum from Name";

Scanner sc = new Scanner(System.in);

try {

Class.forName("org.apache.derby.jdbc.EmbeddedDriver");

} catch(java.lang.ClassNotFoundException e) {

System.err.print("ClassNotFoundException: ");

System.err.println(e.getMessage());

}

try {

con = DriverManager.getConnection(url);

System.out.println("\nWelcome to the JavaDB Contact Database\n");

stmt = con.createStatement();

ResultSet rs = stmt.executeQuery(query);

System.out.println("\n\tNames in Contact Database\n");

while (rs.next()) {

String f = rs.getString("F_Name");

String l = rs.getString("L_Name");

String p = rs.getString("phoneNum");

System.out.printf("%15s %15s %15s", f,l,p);

System.out.println(" ");

}

String choice = "y";

while (choice.equalsIgnoreCase("y"))

{

System.out.println("\n\nJavaDB Insert Contact Information");

System.out.print("\nPlease enter First Name: ");

String fName=sc.next();

System.out.print("\nPlease enter Last Name: ");

String lName=sc.next();

System.out.print("\nPlease enter Phone Number: ");

String phonNum = sc.next();

stmt.executeUpdate("insert into Name " +

"values('" + fName + "', '" + lName + "' , '"+ phonNum +"')");

System.out.print("\nDo you want to continue (y,n)? ");

choice = sc.next();

}

rs = stmt.executeQuery(query);

System.out.println("\n\tNames in Contact Database\n");

while (rs.next()) {

String f = rs.getString("F_Name");

String l = rs.getString("L_Name");

String p = rs.getString("phoneNum");

System.out.printf("%15s %15s %15s", f,l,p);

System.out.println(" ");

}

stmt.close();

con.close();

} catch(SQLException ex) {

System.err.println("SQLException: " + ex.getMessage());

}

}

}

The JavaDBDropNames application dops the Name table the JavaDB database. Here is the application code for the JavaDBDropNames File.

import java.sql.*;

import java.util.*;

public class JavaDBDropNames {

public static void main(String args[]) {

String url = "jdbc:derby:newtest;create=true";

Connection con;

String dropName;

dropName = "drop table Name";

Statement stmt;

try {

Class.forName("org.apache.derby.jdbc.EmbeddedDriver");

} catch(java.lang.ClassNotFoundException e) {

System.err.print("ClassNotFoundException: ");

System.err.println(e.getMessage());

}

try {

con = DriverManager.getConnection(url);

stmt = con.createStatement();

stmt.executeUpdate(dropName);

System.out.println("The table Name has been dropped");

stmt.close();

con.close();

} catch(SQLException ex) {

System.err.println("SQLException: " + ex.getMessage());

}

}

}

All of the files have been compiled and now I will run the applications. First, I need to create the Name table so I will run the JavaDBNames file:

[pic]

The output verifies that the table has been created.

The next step is the run the JavaDBInsertNames file. This file will show any names and phone numbers in the database and allow users to enter any additional entries. Then once the user is done entering information, a query will be executed.

Here is the output:

[pic]

There is a folder entitled Lim478 in the Documents and Settings/Randy folder. Here are the contents of the folder.

[pic]

Here is the property listing of the lim478 folder. It shows 53 files were created and the total size of the database is 1.50 MB. The sample database currently holds 1 table with 2 rows of information. So at the very minimum, JavaDB only takes up 1.50 MB of space.

[pic]

Finally, I will execute the JavaDBDropNames file that will drop the Name table from the lim478 database.

[pic]

The output verifies that the table had been dropped.

The database can also be accessed with the ij tool.

[pic]

ij is typed at the prompt and the ij tool is activated. Now after connecting to the same database and creating the Name table, 2 names are added with different phone numbers.

Here is the result:

[pic]

Finally, the Name table is dropped from the lim478 database. To exit the ij tool, type exit; at the prompt and the command prompt will return to the directory last accessed.

[pic]

Reflective Summary

I feel that my knowledge level of JavaDB is sufficient enough to use it in an embedded database. I still would like to learn more about using JavaDB in a client server connection. My lack of knowledge in JDBC and J2EE prevented me from creating my own GUI application to use. I plan on attempting to complete the application over the holiday break. I had no prior knowledge of embedded databases or specifically, JavaDB. Upon completing this activity I am amazed at the abilities of JavaDB. It seems to have all of the features the larger databases have, but it is a small application. I did not find much information that has tested JavaDB in an application. I would like to know typical response time for executing an SQL statement. Since I could not find independent source material, I believe many articles are going to be written once Java 6 is released. I believe that developers will either report problems with JavaDB or start to create applications.

Summary of Weekly Activities

Week 7

I started to research the various aspects of JavaDB. There is very little information related to JavaDB as it has not been released by Sun. Since it has been around in various names, I will try to research using the other names (Cloudscape and Derby). I have downloaded JavaDB and Netbeans to my laptop and I will read the tutorials to see how to set up the database.

Week 8

I spent most of the week researching. I cannot find many journal articles on JavaDB or Derby. I might have to get most of my information from the non-independent main sources (Sun, IBM, and Apache)

Week 9

The best information I found was on IBM’s website. They have a good article on the technical overview of Cloudscape. I read the tutorial and did set up JavaDB to work with NetBeans. Since I’ve never used Netbeans, I might run into trouble completing a database with a GUI on my own since I don’t have much time.

Week 10

I downloaded a completed Java GUI that implements JavaDB. It worked as planned. So my next step is to review it to see if I can create a different version of it. I was also able to get the ij tool to work in the Windows command line interface. If I cannot create a GUI, I will just run scripts from the IJ tool.

Week 11

I was not able to create a GUI, so I ran the scripts successfully from the IJ tool. Now I need to complete the research and hands on activities. Then I will finish the documentation aspects of the activity.

Week 12

The JDBC topics covered in class were very useful in creating my Java files that interact with JavaDB. I created 3 files and those are listed in the Hands On Documentation Section.

Conclusion

JavaDB has many benefits that will allow developers to use it in numerous applications. Data is moving from the larger databases to smaller ones that can run on any portable system. The hands on demonstration uses a simple application, but JavaDB should have no trouble handling data on a larger scale. To recap some of the features, JavaDB is flexible (can be used as an embedded database or in a client server network), cost effective (free) and secure (authentications are allowed). Many companies will see a huge benefit from using applications that use JavaDB

References

Apache Software Foundation Derby Tools and Utililties Manual Retrieved 10/9/2006 from

Apache Software Foundation Derby Developers Guide Retrieved 10/9/2006 from

Brunner, Robert. Developing with Apache Derby – Hitting the Trifecta: Introduction to Apache Derby Retrieved 10/9/2006 from 128.developerworks/java/library/os-ad-trifecta1/

Press Release Oracle Buys Open SourceSoftware Company Sleepycat

Retrieved 11/2/2006 from

Oracle Data Sheet BerkeleyDB Product Family Retrieved 11/2/2006 from datasheet.pdf

Saunders, Kathy and Anderson, Jean. Cloudscape 10: A Technical Overview. Retrieved 10/9/2006 from 128.developerworks/db2/library/techarticle/dm- 0408anderson/index.html

Suresh, Pagadala and Thiagarajan, Palaniyappan. JAR Files Revealed. Retrieved 10/31/2006 from

Taft, Darryl. Sun adds new Features to ‘Mustang’ Version of Java retrieved 11/2/2006 from

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download

To fulfill the demand for quickly locating and searching documents.

It is intelligent file search solution for home and business.

Literature Lottery

Related searches