Databases Reference
In-Depth Information
a secure (or more secure) programming environment and could run on any
platform regardless of the operating system being used. Now, if one could
create a Java database application, the days of porting programs from one
machine to another were all but gone. The only problem was that Java, like
all new things, was extremely immature and no part of the core language
had database-enabled applications. That shortcoming was noticed and
fixed with the subsequent release of the
package, which contains
the JDBC object model. The JDBC API became the mechanism by which
programmers bridged the gap between their applications and databases. It
defines a number of Java classes that allow programmers to issue SQL
statements and process the results, dynamically learn about a database's
schema etc. It is by far one of the easier to understand object models, and
it is nearly effortless to incorporate it into Java applications.
java.sql
THE PROJECT
So what is it that we're going to set out to do? Let's suppose we wanted
to create a fortune/quotation server that interacts with a Microsoft Access
database and returns an entry and five lucky, random numbers back to the
client's browser. We're going to create this application and support this
functionality using Java and JDBC, but one more thing is needed that
requires us to make some development decisions.
We could create an applet that is downloaded by the browser and pro-
vides a user interface enabling information retrieval from the database.
However, this solution has some notable drawbacks. First and foremost, to
use an applet and interact with a database requires a JDBC driver. There
are many types of commercially available drivers, but they are prohibi-
tively expensive and a project of this scope does not justify the expense.
Another disadvantage to using these drivers is that they typically consist
of a large number of class files. The more files that the browser has to
download over a slow connection, the more irate clients will get at using
the system, eventually abandoning it if it becomes to burdensome (i.e.,
time-consuming) to use. We could opt to use Sun Microsystem's JDBC-
ODBC bridge, which is free, but it is not thread-safe. And unfortunately,
incorporating this driver into an applet requires that we take some addi-
tional steps to make it a trusted component. So now we have to explore
how we can manipulate the browser's built-in security manager so it works,
and this is far more trouble than it's worth for our simple task.
A final disadvantage of using applets is that they can only make connec-
tions back to the machine from which they were downloaded. This means
that if we use a JDBC driver, the database it communicates with must be co-
located with the Web server. It is possible to use a proxy server to circumvent
this restriction, but, short of doing this, we should see if an easier solution
exists (after all, why make more work for ourselves than is necessary?)
Search WWH ::




Custom Search