Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com

The gist. Lookup by first and last name ...

and change this person's phone number.

Every J2EE compliant application server has a JNDI (lookup) service that we can use to find a javax.sql.DataSource.

In the POST handling method we ask it for a connection, that the application server will get us from a pool of connections. This makes it much more efficient than the previous example.

The sdb.war file contains the file testupd.html .

This contains a FORM with two regular text fields and one hidden field, hidden from the user, but sent anyway.

So the first value for 'act' will be 'selc' .

We send the query...

and if the person was found, we send a FORM to the user.

This form is to be handled by the same servlet, dbsupd.

The phone number in a text field, so it can be changed.

When the user sends this form, the value of 'act' will be 'upd'.

We also need to retain the names, so these are sent along. Could have used a session for saving those, but we don't really need it here.

When the user sends the second form, these lines are executed.

=======

NOTES

=======

This example is too simplistic, for the assumption is, that there's only one John Jones in the table, for instance.

=======

Javascript may be disabled in the browser, so this might not work.

This would, but with empty text fields.

=======

There are guidelines for JNDI names, but vendors don't stick to it.

According to JBoss.

IBM.

=======

The servlet's url, in web.xml .

=======

This package, for DataSource, is present in j2ee.jar, distributed in the Java2 Enterprise Edition, so it's not in the Standard Edition.

This JNDI package is in the Standard Edition as of 1.3 .

.