aspose file tools*
The moose likes Servlets and the fly likes opening database in servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "opening database in servlet" Watch "opening database in servlet" New topic
Author

opening database in servlet

alan dool
Greenhorn

Joined: Nov 04, 2001
Posts: 1
Hi all,
I'm sort of new to this, so bear with me ...
I've got a servlet which I want to open a DB2 database and read in the records. The DB2 database resides on an AS400 mid-range computer.
Right now the servlet is just reading in the data from another class (MyCatalog)where the data was hard-coded in, shown below:
public abstract class MyCatalogPage extends HttpServlet {
private MyItem[] items;
private String[] itemIDs;
private String title;
/** Given an array of item IDs, look them up in the
* Catalog and put their corresponding Item entry
* into the items array. The Item contains a short
* description, a long description, and a price,
* using the item ID as the unique key.
* <P>
* Servlets that extend CatalogPage <B>must</B> call
* this method (usually from init) before the servlet
* is accessed.
*/

protected void setItems(String[] itemIDs) {
this.itemIDs = itemIDs;
items = new MyItem[itemIDs.length];
for(int i=0; i<items.length; i++) {
>>>>>>> items[i] = MyCatalog.getItem(itemIDs[i]); <<<<<<<<
}
}
My question is: 1) How do I read these in from the DB2 database??
(I'm a little famaliar with ODBC and JDBC)
Thanks....
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
Architecturally speaking, you need to remove all those instance variables from the servlet since a single servlet instance can be shared by multiple requests. I suggest you create another class to handle the JDBC query - it will be easier to test off-line.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: opening database in servlet