|
SYS-CON.TV Webcasts
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
Top Links You Must Click On
Product Reviews Building a True Database Solution
Building a True Database Solution
By: Alan Williamson
Sep. 1, 1997 12:00 AM
In our last article, we introduced what is now our column project: Informer. Informer is a small contact database application that is designed to provide contact information about various personnel over an Intranet or Internet. The idea for this project evolved from one of our N-ARY designers, Frode Hegland, who wanted to make information more available to people without saddling them with horrendous client-side applications. So, we came up with the Informer. Over this series of columns, we will be building new features into the Informer, showing you how easy Java can make building what, on the face of it, seems to be a rather complex system.
Three-Tiered Solutions A better solution would be to pass all database requests onto another piece of software that had all the drivers installed and a connection established to the database. This software could live on the Web server and pass requests between the client applet and the database. Fortunately, many commercial solutions are available to the developer for this very case. Symantec's dbAnywhere is one of the most popular and most flexible. dbAnywhere comes in two parts: the server software and the client API classes. The server software sits and executes on the server, listening for incoming connections on a specific TCP port which defaults to 8889. The server software knows nothing of the databases available to it and therefore, to the relief of many, setting this server up is a piece of cake. Simply start it up and leave it to run in the background. The real magic is in the Java dbAnywhere API. The dbAnywhere API gives the developer all the access facility that is available under JDBC and then some. Everything is done from the applet, with the dbAnywhere suite simply passing requests on to the server and then collating the results back again. For example, consider the code snippet shown in Listing 1.
This code would be situated within the Java applet and, when run, first attempts to make a connection to the dbAnywhere server situated on the N-ARY Web server at port 8889. Once connected, it tries to open up a connection to the database "Contacts", using the user name "alan" and password "runrig". If anything goes wrong, an exception is thrown. Possible reasons for an exception being thrown include: Once a connection has been opened, SQL statements can be constructed and sent to the database, with the results coming back in much the same way as JDBC processes them. But if all that seems a bit too complicated to begin with, or your knowledge of SQL and databases is a bit rusty, have no fear. In true Visual Café fashion, a lot can be achieved before we even get to editing source code. The remainder of this article will look at setting up the database connection and making the first version of the Informer, which will give basic database functionality to the user; adding new records and modifying existing records and basic navigation.
Step #1: Database Selection Setting the ODBC driver up is a simple matter of adding a new database table using the 32bit ODBC' utility, situated in the Control Panel, and giving it a logical name. in this instance, I used "Contacts". Once completed, believe it or not, the hardest part is over. Before you start to build the applet, ensure that the dbAnywhere server is up and running. Now we are ready to code.
Step #2: Project Creation Once these steps have been completed, the wizard will create the first version of the applet, which at this stage doesn't look at all pretty. So, we shall change the attributes of the fields and end up with something that looks like the applet shown in Figure 2. Configuring the attributes was a simple matter of clicking on the field and changing the various parameters in the Properties window. Then, by running the applet the source compiled and a connection to the dbAnywhere server was made. It was good to see this all happened without even a hint of an error - which to the first time developer is never a bad thing. That's it! The first version of Informer is complete. We have full database functionality and an applet that is ready for widespread deployment. As I said in previous articles, remember to copy the Symantec classes into the directory where the applet will be downloaded from; otherwise, the browser won't be able to find all the dbAnywhere classes.
Summary Reader Feedback: Page 1 of 1
Enterprise Open Source Magazine Latest Stories . . .
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||