GeeCON Prague 2014*
The moose likes JDBC and the fly likes Using DataSource object with JNDI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "Using DataSource object with JNDI" Watch "Using DataSource object with JNDI" New topic
Author

Using DataSource object with JNDI

Ricky James
Ranch Hand

Joined: Mar 26, 2007
Posts: 83
Hi,

I am working on this exercise and would be thankful if somebody could point me in the right direction to tackle it.

Create a servlet that displays a list of customers (From the customer table of the database). Use the HTML table to organize the display.

Hint: Use a Java Bean, e.g. CustomerBean that has the fields of �First Name�, �Last Name� and �Date of Birth�. And when the query returns the result set, you will need to populate each CustomerBean and add them to an ArrayList. Then return the collection object to the servlet, loop through the collection and display the result.


I have learnt to display data in an html table directly from a servlet connected to a database via jdbc. But I do not understand how to use a JavaBean to attain that as advised in the 'hint'.

I do not expect the solution but suggestions are welcome. If you know of any online resource, or a book that deals with this topic, it would be really helpful.

Thanks
Ricky

[ April 02, 2007: Message edited by: Ricky James ]
[ April 02, 2007: Message edited by: Ricky James ]
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2501
    
    8

If you're using Tomcat, then this is a good guide:
Apache Tomcat 6.0 JNDI Datasource HOW-TO.
Shows how to configure the thing in tomcat, and how to use it in your servlet.

The use of the javabean is almost completely explained in your assignment:

Create a bean with variables to hold the table's values.
Query the table, and for each row found:Create a new bean.
Populate the bean's variables with the table values.
Add the bean to your array.

Open html table

Then, for each bean in the array:
create a table row,
get the current bean's property values
enter these values in the table columns

close the html table

Regards, Jan
[ April 02, 2007: Message edited by: Jan Cumps ]

OCUP UML fundamental and ITIL foundation
youtube channel
Ricky James
Ranch Hand

Joined: Mar 26, 2007
Posts: 83
Originally posted by Jan Cumps:
If you're using Tomcat, then this is a good guide:
Apache Tomcat 6.0 JNDI Datasource HOW-TO.
Shows how to configure the thing in tomcat, and how to use it in your servlet.

The use of the javabean is almost completely explained in your assignment:

Create a bean with variables to hold the table's values.
Query the table, and for each row found:Create a new bean.
Populate the bean's variables with the table values.
Add the bean to your array.


Regards, Jan

[ April 02, 2007: Message edited by: Jan Cumps ]


Thanks again Jan. I've visited this site but I am looking for a resource which has specific examples regarding this.
Ricky
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2501
    
    8

If it's an assignment, I think the solution has to come from yourself.
Read the info, and apply it.
Regards, Jan
Ricky James
Ranch Hand

Joined: Mar 26, 2007
Posts: 83
Originally posted by Jan Cumps:
If it's an assignment, I think the solution has to come from yourself.
Read the info, and apply it.
Regards, Jan


You are correct Jan.
And I am trying.
Thanks
Ricky
 
GeeCON Prague 2014
 
subject: Using DataSource object with JNDI