Free Evaluation Software for WAN-based Data Distribution

PC Magazine

  PC Tech

Server-Side JavaScript

Introduction

Why Server-Side JavaScript?

The Architecture

Diagram: How LiveConnect Works

Session Management

File and Mail Services

Database Access

Accessing Other Languages



X10.com - The SuperSite for Home Automation!

FREE investing information on 400 top companies - click here!

 
  Categories
World Wide Web

Server-Side JavaScript
Database Access

Continued from File and Mail Services

Server-side JavaScript provides a complete Web-to-database solution, and whether you want to create a database-query engine or a complete database-management system, you can use server-side JavaScript's LiveWire Database Service to help get the job done. The service supports native drivers for DB2, Informix, Oracle, and Sybase, as well as for databases that conform to the ODBC standard. Features supported by the service include database pooling, pass-through SQL, cursors, and stored procedures.

Keep in mind though that your server environment ultimately determines the types of databases you can work with, as well as the features of LiveWire Database Service that are available to you. So before you begin any project planning or work on a Web-to-database application, you should determine whether the service works within your current server environment. If the service does not support your current server environment, you may need to modify or upgrade your HTTP server, database client, or ODBC components. And even if the service works, you'll still need to make sure that it supports the features you need.

There are four basic steps for working with a database: mapping the database structure, establishing a connection to the database, handling database transactions as necessary, and finally, releasing the connection. Let's explore these steps in more depth.

Map out the database structure. To extract records from a database, you may need to know the names of tables and columns. To update data, you may need to know the acceptable data types, the maximum allowable data size, whether the column accepts null values, and other pertinent information. If you are working with an existing database, obtaining this information before coding your application is fairly easy. But if you're creating a new database for the application, you should create a prototype of the database before you start programming the application. Once the database structure is in place, map out its properties, writing down the pertinent information such as table names, column names, and acceptable data types. This makes working with the database much easier.

Establish a connection. LiveWire Database Service provides two ways to connect to a database: shared connections and pooling. A shared connection is accessible to a single user at a time; other users are locked out of the database as long as that user is connected. With pooling, on the other hand, multiple users can access a database at the same time via a connection pool.

Think of a connection pool as a jar full of access cards. When a user needs access to a database, he takes a card out of the jar. When others need access to the database, they can take cards out of the jar, and so on. If at any time the jar becomes empty, the next user must wait until a card is returned to the jar.

With either connection method, application performance is often tied directly to the availability of database connections. If no connection is available when a user needs one, the application has to try to obtain one and the user has to wait. Because of this, database connections are usually established on the application's initial page and then made available to users on an as-needed basis. The exception is when your application requires users to log on to the database with a user-specific sequence. In this case, you would probably want to establish the connection when it's needed. For example, if users must access the database using their login names and passwords, you should establish connections the first time users try to access the database.

Handle transactions. Once you establish a connection, users can perform any actions permitted by their profile, which may include database queries and updates. Database queries can be handled with pass-through SQL, read-only cursors, and stored procedures. Database updates can be handled with pass-through SQL, updateable cursors, and stored procedures.

Whenever you update a database, you should use explicit transaction controls. With transactions, you perform a group of actions together. If the actions are successful, you update the database. If any of the actions are unsuccessful, you restore the database to its original state.

Release the connection. When a user completes a transaction, you usually want to release the database connection. Releasing the connection doesn't necessarily mean breaking the connection with the database. With a shared connection, you release the lock on a database object, which ensures that other users can access the database. With a pooled connection, you return the connection to the pool, which ensures that it is available to other users.

Next: Accessing Other Languages

Published as PC Tech Feature in the 5/4/99 issue of PC Magazine.

Related Links
JavaScript-powered Stylesheets -- PC Tech
DHTML That Works in Both IE and Navigator -- PC Tech
JavaScript -- DevHead
ScriptHead Archive -- DevHead
 
JavaScript Programming Courses -- ZDU

 
 SPONSORED LINKS
QUANTUM  Storage solutions to count on 24 hours/day, CLICK HERE
Sprint  FrameRelay: See why users rate Sprint #1 for frame relay
Beyond.com  Click here for free software!
Software  X10.com -- The SuperSite for Home Automation
Books  Buy a gift for MOM, a book from barnesandnoble.com
 ZDNET FEATURED LINKS
Freebies!  The latest FREE files - yours to download and keep!
Shop Smart  Compare prices on over 7,000 computer products & save
Contest  Win a Diamond MP3 Rio from ZDNet Auctions!
 MAGAZINE OFFERS
Free Issue  Get a risk-free issue of RED HERRING magazine today!

TOP
Copyright (c) 1999 Ziff-Davis Inc.