Advertisment

Extract Data with DataTables

author-image
CIOL Bureau
Updated On
New Update

A tabular display of data on a Web application is nothing new, nor is the

ongoing struggle by developers to make it more and more intuitive and

functional-selectable, editable and sortable. The DataGrid components, such as

the one provided by ASP.NET, have been a boon for developers. Whether it's to

pull data from a database, sort or update data, everything can be done by

writing just a few lines of tags and even fewer lines of code. Here we look at a

DataGrid-like component called DataTable provided by JavaServer Faces technology

for J2EE Web applications. 

































Direct Hit!
Applies to: Java

developers
USP: Quick

display of database tables
Primary Link: href="http://www.myfaces.org">www.myfaces.org
Google keywords:

jsf datatable, javaserver faces

datatable 


In the first part of this series, (MyFaces, page 81, PCQuest, July 2005) we

walked you through setting up MyFaces (an open source implementation of JSF

technology) and coding a small JSF Web application. For this article, we assume

that you have already set up MyFaces on PCQLinux 2005. 



Prerequisites 

For the code in this article we will retrieve data

from a MySQL database named 'contact' and display it in the grid. To set up
MySQL on PCQLinux 2005, refer to the MySQL section in the article JDBC Drivers,

page 76, PCQuest, March 2005.

Next, create the database 'contact' as:



mysqladmin -u root -p create contact


When prompted, type in the password for the MySQL root user. Next, issue:



mysql -u root -p contact 



Again supply the password and you will be dropped into a mysql>prompt. At

this prompt, create a table named 'info' as:



create table info(name varchar(20), address varchar(50),email

varchar(30));



Populate the table with data as:



insert into info (name,address,email) values href="mailto:('ab','Delhi','ab@foo.com">('ab','Delhi','ab@foo.com');



Insert some more contact info by issuing the above insert statement with

different names, addresses and e-mail ids.


Read more at PCQuest

tech-news