Hi,

I'm no expert Java programmer but I do something similar to allow users to
plot laboratory Quality Control results graphically. I have included a few
snippets of my code below.
The user fires off the first servlet that queries my (MS Access) database
and returns all valid parameters to the user as (multiple-selectable)
Combo-boxes in an HTML Form.
The user selects any combination from these Combo boxes, hits "submit" and
the parameters are submitted to a second servlet that builds the SQL code
(using the code below). The user can make any combination of selections from
the (4) combo boxes and the same code will always handle it (for clarity I
have cut out all non-relevant code).

Hope this helps.

Regards,   Billy.



//Define required variables to store multiple choices...

String[] userDepartments;
String[] userAnalysers;
String[] userControls;
String[] userTests;
=========================

//Load multiple choices (from HTML Form) into arrays...

userDepartments = req.getParameterValues("D");
userAnalysers = req.getParameterValues("A");
userControls = req.getParameterValues("C");
userTests = req.getParameterValues("T");

D, A, C and T contain the values returned from the HTML multiple-choice
combo-boxes
================================

//Build up the SQL string from (any number of) returned parameters...

userDepartmentsNo = userDepartments.length;
userAnalysersNo = userAnalysers.length;
userControlsNo = userControls.length;
userTestsNo = userTests.length;

String DeptsSQL = "";
String AnalsSQL = "";
String ControlsSQL = "";
String TestsSQL = "";


for(int a=0; a<userDepartmentsNo; a++){
if(a==(userDepartmentsNo-1)){DeptsSQL = DeptsSQL + "'" + userDepartments[a]
+ "'";}
  else{DeptsSQL = DeptsSQL + "'" + userDepartments[a] + "',";}
}
DeptsSQL = " AND ([Results].[Dept] in (" + DeptsSQL + "))";


for(int a=0; a<userAnalysersNo; a++){
if(a==(userAnalysersNo-1)){AnalsSQL = AnalsSQL + "'" + userAnalysers[a] +
"'";}
  else{AnalsSQL = AnalsSQL + "'" + userAnalysers[a] + "',";}
}
AnalsSQL = " AND ([Results].[Anal] in (" + AnalsSQL + "))";


for(int a=0; a<userControlsNo; a++){
if(a==(userControlsNo-1)){ControlsSQL = ControlsSQL + "'" + userControls[a]
+ "'";}
  else{ControlsSQL = ControlsSQL + "'" + userControls[a] + "',";}
}
ControlsSQL = " AND ([Results].[Material] in (" + ControlsSQL + "))";


for(int a=0; a<userTestsNo; a++){
if(a==(userTestsNo-1)){TestsSQL = TestsSQL + "'" + userTests[a] + "'";}
  else{TestsSQL = TestsSQL + "'" + userTests[a] + "',";}
}
TestsSQL = " AND ([Results].[Test] in (" + TestsSQL + "))";


=============================

//Append the SQL part-statements into final SQL statement...

mysqlStatement = "SELECT [Dept], [Anal], [Material], [Date], [Time], " +
                 "[Test], [Result], format(Results.[Date],'dd'), " +
                 "[Id], [CtrlBatchNo], [ReagentBatchNo], [TargetValue],
[SD], [Units], " +
                 "format(Results.[Date],'dd/mm/yy'), format(Results.[Time],
'hh:mm'), " +
                 "format(Results.[Date],'mm'), format(Results.[Date],'yy'),
[Decimals], [MaterialDescription] FROM [Results] " +
                 "WHERE ([Results].[Date] between #" + tDateFrom + "# and #"
+ tDateTo + "#) AND ([Results].[Exclude] = false) " +
                  DeptsSQL + AnalsSQL + ControlsSQL + TestsSQL;

//Then execute your SQL, get your result set returned and process as
required.


================END======================




-----Original Message-----
From: Tom Kochanowicz [mailto:[EMAIL PROTECTED]]
Sent: 10 May 2002 08:03
To: [EMAIL PROTECTED]
Subject: Re: Using the getParameterValues


Yes,

        What I am doing is setting up a web enabled data warehouse to study
pancreatic cancer patients. The mission is to find characteristics that are
common in these patients and to see if their is a pattern (e.g. sex, race,
demographics, etc.) that shows a higher probability of getting pancreatic
.....
*****************************************************************

This email has been Virus Scanned.

Privileged/Confidential Information and/or Copyright Material may
be contained in this e-mail. The information and Material is
intended for the use of the intended addressee. If you are not
the intended addressee, or the person responsible for delivering
it to the intended addressee, you may not copy or deliver it to
anyone else or use it in any unauthorised manner. To do so is
prohibited and may be unlawful. If you receive this e-mail by
mistake, advise the sender immediately by using the reply
facility in your e-mail software.


Thank you.
Information Technology Department
Belfast City Hospital Trust

*****************************************************************

Reply via email to