//connect to the database, pose the query and obtain the results
try
{ Class.forName(driverName).newInstance();
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
What does this do? It can only do ANYTHING via side-effects.
Does the no-parameter constructor have side-effects?
How long do the side-effects remain effective?
con = DriverManager.getConnection(connectionURL);
Beware also of static hidden in your calls. Apparently, this
is synchronized but it is also a static method.
->-----Original Message-----
->From: Graham, Billy [mailto:[EMAIL PROTECTED]]
->Sent: Thursday, September 20, 2001 4:48 AM
->To: [EMAIL PROTECTED]
->Subject: FW: Inconsistent behaviour in Servlet output
->
->
->Hi Milt (& Pierre-Yves & others),
->[This is the 4th time I've sent this e-mail - it keeps
->getting returned for
->being too large > 300 lines, so I've been compressing the
->code shown at
->bottom (but now less readable)]
->
...........................................
->import javax.servlet.*;
->import javax.servlet.http.*;
->import java.io.*;
->import java.sql.*;
->import java.util.*;
->
->public class RequestScreen extends HttpServlet
->{
->public void ProcessHeader(java.io.PrintWriter out){
-> out.println("<html><head><title>Contents of the QSee
->Database</title>");
->
-> //Function to get Client document width and height
-> out.println("<SCRIPT language=\"javascript\">");
-> out.println("function getDims(Dim) {");
-> out.println("var height, width;");
-> out.println("if (document.all) height =
->document.body.offsetHeight, width
->= document.body.offsetWidth;");
-> out.println("else if (document.layers) height =
->window.innerHeight, width
->= window.innerWidth;");
-> out.println("if (Dim=='H') return height; else return width;");
-> out.println("}");
-> out.println("</SCRIPT></head><body>");
-> out.println("<center><h3>Please make your selection from the lists
->supplied</h3></center>");
-> out.println("<FORM ACTION=\"http://localhost/servlet/QSee4\"
->METHOD=\"GET\">");
-> // Get Client screen Width and Height
-> out.println("<SCRIPT>document.write('<INPUT TYPE=\"hidden\"
->NAME=\"sw\"
->VALUE=\"' + getDims(\"W\") + '\">');</SCRIPT>");
-> out.println("<SCRIPT>document.write('<INPUT TYPE=\"hidden\"
->NAME=\"sh\"
->VALUE=\"' + getDims(\"H\") + '\">');</SCRIPT>"); }
->
->public void ProcessFooter(java.io.PrintWriter out){
->//get the required order
-> out.println("<center><table WIDTH=\"40%\">");
-> out.println("<tr ALIGN=\"LEFT\"><td
->WIDTH=\"40%\">Department</td><td>");
-> out.println("<INPUT TYPE=\"RADIO\" NAME=\"o1\" VALUE=\"1\"
->CHECKED>");
-> out.println("<INPUT TYPE=\"RADIO\" NAME=\"o1\" VALUE=\"2\">");
-> out.println("<INPUT TYPE=\"RADIO\" NAME=\"o1\" VALUE=\"3\">");
-> out.println("<INPUT TYPE=\"RADIO\" NAME=\"o1\"
->VALUE=\"4\"></td></tr></table></center><BR>");
-> out.println("<center><table WIDTH=\"40%\"><tr ALIGN=\"LEFT\"><td
->WIDTH=\"40%\">Analyser</td><td>");
-> out.println("<INPUT TYPE=\"RADIO\" NAME=\"o2\" VALUE=\"1\">");
-> out.println("<INPUT TYPE=\"RADIO\" NAME=\"o2\" VALUE=\"2\"
->CHECKED>");
-> out.println("<INPUT TYPE=\"RADIO\" NAME=\"o2\" VALUE=\"3\">");
-> out.println("<INPUT TYPE=\"RADIO\" NAME=\"o2\"
->VALUE=\"4\"></td></tr></table></center><BR>");
-> out.println("<center><table WIDTH=\"40%\"><tr ALIGN=\"LEFT\"><td
->WIDTH=\"40%\">Control</td><td>");
-> out.println("<INPUT TYPE=\"RADIO\" NAME=\"o3\" VALUE=\"1\">");
-> out.println("<INPUT TYPE=\"RADIO\" NAME=\"o3\" VALUE=\"2\">");
-> out.println("<INPUT TYPE=\"RADIO\" NAME=\"o3\" VALUE=\"3\"
->CHECKED>");
-> out.println("<INPUT TYPE=\"RADIO\" NAME=\"o3\"
->VALUE=\"4\"></td></tr></table></center><BR>");
-> out.println("<center><table WIDTH=\"40%\"><tr ALIGN=\"LEFT\"><td
->WIDTH=\"40%\">Test</td><td>");
-> out.println("<INPUT TYPE=\"RADIO\" NAME=\"o4\" VALUE=\"1\">");
-> out.println("<INPUT TYPE=\"RADIO\" NAME=\"o4\" VALUE=\"2\">");
-> out.println("<INPUT TYPE=\"RADIO\" NAME=\"o4\" VALUE=\"3\">");
-> out.println("<INPUT TYPE=\"RADIO\" NAME=\"o4\" VALUE=\"4\"
->CHECKED></td></tr></table></center><BR>");
->//get the required dates
-> out.println("<center><table border>");
-> out.println("<tr><td>");
-> out.println("From: <INPUT TYPE=\"TEXT\" NAME=\"from\" SIZE=\"12\"
->MAXLENGTH=\"12\">");
-> out.println("</tr><td>");
-> out.println("To: <INPUT TYPE=\"TEXT\" NAME=\"to\" SIZE=\"12\"
->MAXLENGTH=\"12\">");
-> out.println("</td></tr><td>");
-> out.println("Values: <INPUT TYPE=\"TEXT\" NAME=\"values\"
->VALUE=\"31\"
->SIZE=\"12\" MAXLENGTH=\"12\">");
-> out.println("</td></tr></table></center>");
-> out.println("<INPUT TYPE=\"submit\" VALUE=\"Submit\">");
-> out.println("</FORM></body></html>");
-> out.flush(); }
->
->public void ProcessResults(java.io.PrintWriter out, ResultSet
->myResultSet,
->String myTableType){
->//format and present results
->try
->{ /* If there is data in the ResultSet, get the ResultSet's
->metadata,
-> e.g. number of columns, column labels, etc. */
->
->if(myResultSet.next()){
-> ResultSetMetaData rsmd = myResultSet.getMetaData();
-> int colCount = rsmd.getColumnCount();
->//set up an HTML table
-> out.println("<center><table border><tr><td>");
->//obtain and print the database fields column labels
-> out.println("<th>" + rsmd.getColumnLabel(1) +"</th></td>");
-> String myListValue;
-> String myListName;
-> boolean OneSelected = false;
->//obtain and print out each record of the database
-> out.println("<td><SELECT MULTIPLE SIZE=\"5\" NAME=\"" +
->myTableType +
->"\">");
-> do{if (myTableType=="Tests"){
-> myListValue = myResultSet.getString(1);
-> myListName = myResultSet.getString(2) + " (" +
->myListValue + ")";}
-> else{
-> myListValue = myResultSet.getString(1);
-> myListName = myListValue;}
->
-> if (OneSelected){out.println("<OPTION VALUE=\"" +
->myListValue + "\">"
->+ myListName);}
-> else {out.println("<OPTION SELECTED VALUE=\"" +
->myListValue + "\">" +
->myListName);
-> OneSelected = true;}
-> }while(myResultSet.next());
->
-> out.println("</SELECT></td></tr>");
-> //close the HTML table
-> out.println("</table></center>");
->}
-> else{//if there are no records in the database
-> out.println("No records could be found"); }
->}
-> catch(Exception e)
-> {out.println(e);}
->}
->
->public void doGet (HttpServletRequest req, HttpServletResponse resp)
->throws ServletException, java.io.IOException
->{//set content type of the response and set no caching
->resp.setContentType("text/html");
->resp.setHeader("Cache-Control", "no-cache");
->resp.setHeader("Pragma", "no-cache");
->
->//create PrintWriter to write the HTML results page
->java.io.PrintWriter out = new
->java.io.PrintWriter(resp.getOutputStream());
->//create the SQL querys
->String DepartmentsQ = "SELECT [Department] from [Departments] GROUP by
->[Department]";
->String AnalysersQ = "SELECT [AnalyserName] from [Analysers]";
->String ControlsQ = "SELECT [CtrlName] from [Controls] GROUP
->BY [CtrlName]";
->String TestsQ = "SELECT [Analyte], [Description] from
->[AnalyteDetails] GROUP
->BY [Analyte], [Description]";
->//specify that the JDBC-ODBC bridge is being used
->String driverName ="com.ms.jdbc.odbc.JdbcOdbcDriver";
->//identify the QSee database as the connectionURL
->String connectionURL ="jdbc:odbc:QSee";
->//initialise connection, statement and result set variables
->Connection con = null;
->Statement stmt = null;
->ResultSet rs = null;
->//connect to the database, pose the query and obtain the results
->try
->{ Class.forName(driverName).newInstance();
-> con = DriverManager.getConnection(connectionURL);
-> stmt = con.createStatement();
-> ProcessHeader(out);
-> rs = stmt.executeQuery(DepartmentsQ);
-> ProcessResults(out, rs, "Departments");
-> rs = stmt.executeQuery(AnalysersQ);
-> ProcessResults(out, rs, "Analysers");
-> rs = stmt.executeQuery(ControlsQ);
-> ProcessResults(out, rs, "Controls");
-> rs = stmt.executeQuery(TestsQ);
-> ProcessResults(out, rs, "Tests");}
->catch (Exception e){out.println(e);}
->
->ProcessFooter(out);
->try{if (con != null){con.close();}}
->catch(Exception e) {out.println(e);}}
->}//end
->
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html