This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

opening database in servlet  RSS feed

alan dool
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
William Brogden
Author and all-around good cowpoke
Posts: 13078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!