The connection objects should be assigned to local, not instance variables.
Mark -----Original Message----- From: anilkumar [mailto:[EMAIL PROTECTED]] Sent: Tuesday, June 25, 2002 8:48 AM Hi, In Servlet try to maintain 3 database connection objects. Get the parameters from HTML form, send these parameters, sql query, connection object to a particular method. Put the result in one of Collection class and send this collection class to client side. I written sample code. I think it will be helpful.... Example: public class MYServlet extends HttpServlet { Connection dbconn1 = null; Connection dbconn2 = null; Connection dbconn3 = null; public init() { // Get the three database connection objects and assign to class variables; } public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException { // Get the HTML parameters // Call the same getResults method for 3 different databases. Vector allResults = new Vector(); allResults.addElement(getResults(necessary paraments)); } public Vector getResults(String sqlquery, Connection conn, String parameter1, String parameter2, ...) { // Execute the sql statment. // Move all the values into the vector Vector v = new Vector(); while (rst.next()) { Vector row = new Vector(); row.addString(rst.getString(1)); // fetch all the columns // add this vector to return vector; v.addElement(row); row = null; } return v; } } bye.. ANIL -----Original Message----- From: A mailing list for discussion about Sun Microsystem's Java Servlet API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of Christian Bollmeyer (GMX) Sent: Tuesday, June 25, 2002 1:35 AM To: [EMAIL PROTECTED] Subject: Re: query three remote databases at the same time Hi Alil, probably I didn't exactly understand the problem, but what hinders you from issuing three SQL queries instead of one, using three different database connections, if necessary? Then walk over the ResultSets and finally present the cumulated results to the client. The tricky thing will be performance, for your servlet will have to wait until either all three queries returned or timeout occured. As I understand, asynchronous solutions are out of discussion when it comes to displaying the overall result. But still, at least I'd execute the queries in parallel. Guess I'd delegate the whole problem to some specialized Controller class handling the de- tails of information retrieval (which would spawn appropriate threads for each database query and keep general control over the whole issue), return the results in a Vector (Vector is slow, but thread-safe) or something and finally let the servlet display the overall result. Note that the servlet will have to wait during the entire process, so I'd suggest to either do all that stuff in synchronized code (atomic i.e. single thread behavour is necessary in this case anyway) or - better - have the servlet implement 'SingleThreadModel' (just a 'tagging interface' anyway, look up the API docs for details). Can't explain the details here, but 'SingleThreadModel' at minimum gives the server a chance to spawn multiple servlet instances (though this behavior is implementation specific), whereas 'synchronized' may block the entire application. Regardless of how you implement the final solution, be watchful about this issue in particular, especially if the queries may take some time (always keeping a timeout in mind). HTH, -- Chris (SCPJ2) ----- Original Message ----- From: Halil AKINCI To: [EMAIL PROTECTED] Sent: Monday, June 24, 2002 10:33 AM Subject: query three remote databases at the same time Hi, How can I query three remote databases at the same time using servlet? I want to send a parameter this databases using a HTML form. Remote servers receive this parameter, execute query and send results to client. I want to display all results (that remote databases send) one HTML page. How can do that? ___________________________________________________________________________ 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 ___________________________________________________________________________ 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 ___________________________________________________________________________ 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
