Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Create a wiki system using Derby, Part 1: The basic system and regular expressions

Daniel Wintschel (daniel@humandoing.net), Author and developer
Daniel Wintschel is a regular guy who derives great excitement from solving business problems, streamlining processes, and writing all sorts of Java code. He loves coffee and is currently seeking development opportunities on a telecommuting basis from Singapore. If you are bored one day, you can read more about him.

Summary:  One form of communication gaining popularity today is the wiki, which enables users -- not just administrators -- to make changes to a Web site directly through the Web interface, automatically adding features, such as formatting and outgoing links. In this two-part series, you use the ability to embed Apache Derby in a Web application server to create a simple wiki system. This first tutorial gives you an overview of the basic system and regular expressions.

View more content in this series

Date:  18 Oct 2005
Level:  Intermediate PDF:  A4 and Letter (549 KB | 28 pages)Get Adobe® Reader®

Activity:  4655 views
Comments:  

Before you start

This is the first part in a two-part tutorial series that demonstrates how easy it is to embed Derby as a full-featured relational database into a Web application server. In this first tutorial, you examine one way to set up Derby within your application server and, subsequently, how you can use Derby to provide a back-end data store for dynamic content within an application. For the example in this series, you're going to develop a simple Web-based wiki. To follow along with this first tutorial, you should feel comfortable working with simple servlets and have a basic understanding of Java™ Database Connectivity (JDBC). You use Apache Ant to build the application, so being comfortable running an Ant build file won't hurt either. This tutorial also covers some basics about regular expressions, which you use to parse and display wiki text in a browser.

About this tutorial

With the recent contribution made by IBM to the open source community -- donating the source code for their Cloudscape database to the Apache Foundation (who renamed the open-sourced version to Derby) -- you now have yet another great open source database available to use within your applications. One of the nice features of Derby is that being, in essence, a baby brother to IBM DB2®, it provides users with a great stepping stone. Should you need or want to start your project on a smaller budget with a slightly less-powerful database, you can use Derby for your initial development, and then later you can make a virtually seamless move to a commercial alternative, such as DB2 (see Resources for articles on migrating Derby to DB2).

In this tutorial, you'll see how easy it is to embed Derby into a Web application, which can then be used to provide data and dynamic content for that application. Other items that this tutorial covers include the history and definitions of the wiki and a description of working with regular expressions. This tutorial is structured as follows:

  • What's a wiki? -- Briefly discusses the history of the wiki, what a wiki is, and the intended purpose of the wiki concept.
  • Set up the system -- Provides an overview of how to set up the application and how to embed Derby for use within the application. Then you walk through the build process and get the wiki up and running.
  • Create a user account -- Demonstrates how to use the wiki pages to create a wiki user account.
  • Create pages -- Shows you how to create pages in the wiki and demonstrates the wiki syntax that is supported by the wiki implementation.
  • Use regular expressions -- Details some of the regular expressions used within the application and how to use the available Java APIs to do something useful with the regular expressions.
  • Understand regular expressions -- Discusses more about how to learn regular expressions.

Prerequisites

This tutorial assumes that you have a basic knowledge of the Java Servlet API and JDBC.

To run the example code in this tutorial, perform the following steps:

  1. Download and install the following applications
  2. Make sure the environmental variables outlined in Table 1 are defined in your shell.

Table 1. Environmental variables
Variable nameRequired setting
TOMCAT_HOMESet to the root folder of your Tomcat installation
DERBY_HOMESet to the root folder of your Derby installation
ANT_HOMESet to the root folder of your Ant installation
JAVA_HOMESet to the root folder of your Java installation
PATHEnsure that ANT_HOME/bin is in your PATH

  1. Extract the supplied ZIP file (see the Download section for the file) to your preferred location (this will be the project root). The project is laid out as follows:
    /Wiki/
         /conf/   > contains DDL (data definition language)
         /deploy/ > created by ANT (will contain WAR file)
         /src/    > contains Java source code
         /web/    > contains JSPs and web.xml, etc.
         /build.xml > ANT build file	
    

  2. The last thing you need to do is modify the /web/WEB-INF/web.xml file to specify where you want Derby to create your wiki database. In my case, I've set the derby.system.home property in the web.xml file to be W:\Development\WikiDB. See the following example taken from the web.xml file:
    <servlet>
      <servlet-class>net.humandoing.wiki.WikiServlet</servlet-class>
      <servlet-name>WikiServlet</servlet-name>
      <init-param>
        <param-name>derby.system.home</param-name>
        <param-value>W:\Development\WikiDB</param-value>
      </init-param>
    </servlet>
    

Note: Make sure that the value you specify is a directory and that it already exists. Second, you don't need to put a trailing slash. Third, if you are on a *nix-based system, your path would look something like /development/WikiDB, but you can create this directory wherever you want to.

If you don't specify a value or a valid value for this property, the application creates the wiki database under the Tomcat directory webapps/wiki/WEB-INF/WikiDB. This is OK, but it means that if you redeploy the wiki, any data that you entered into your wiki will be gone.

1 of 10 | Next

Comments



Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Open source, Java technology, Information Management
ArticleID=133170
TutorialTitle=Create a wiki system using Derby, Part 1: The basic system and regular expressions
publish-date=10182005
author1-email=daniel@humandoing.net
author1-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Try IBM PureSystems. No charge.