lightweight directory access protocol (ldap) is fast becoming a de facto access method for common directory information. xml is now the standard for data exchange on the web. the relational database, a technology for modeling data in table form, has always been the most popular way to store and retrieve application data.
how do these three technologies come together, other than the fact that theyre all buzzwords in the technology world? theyre all a way to represent data, which you can easily access using the powerful set of query capabilities they each provide. ldap data can be queried using ldap directory search, xml data can be queried using xpath, and relational database data can be queried using sql.
in this article i describe an employee information application that can use all three methods to store and query data. youll learn how to construct each kind of query and write java code to retrieve data, respectively. its of great value to you as a developer because youre likely to come across systems implemented using one of these technologies and be asked to develop applications on top of it.
the employee information application
{ 【程序编程相关:The Great Java Jobs 】 figure 1 shows the user interface of a simple employee information application, organizing employees by last name, first name, phone, and e-mail address.each employee can be represented as a java object (seen below). in the next few sections, i discuss how this data can be represented and queried in various ways.
class employee 【推荐阅读:Single Aspect-Orient】
private string lastname; 【扩展信息:SOA What? @ JDJ】 private string id; private string firstname; private string phone; private string e-mail; }relational database and sql
the relational database is a common way to model application data. you can model all the employee information described above into one table called employee. the id will be a unique key used to identify an employee.create table employee
{ id varchar(64) not null; lastname varchar(64) null; firstname varchar(64) null; phonenumber varchar(12) null; e-mail varchar(64) null } create unique index indxemp on employee (id)to retrieve data from relational database, use sql. most developers are familiar with sql, so i wont explain it here. a standard sql looks like this:
select <field1>, <field2>
from <table> where <field1> = <value1> and <field2> = <value2> and ...querying a relational database in java code
to access the database using java, you can use jdbc, the standard api for executing sql statements in any relational database. with jdbc, different drivers can be installed dynamically to access different databases. as a result, your code remains the same ... 下一页