Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@apache.org Received: (qmail 89640 invoked from network); 7 Feb 2002 00:56:05 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 7 Feb 2002 00:56:05 -0000 Received: (qmail 22418 invoked by uid 97); 7 Feb 2002 00:55:46 -0000 Delivered-To: qmlist-jakarta-archive-tomcat-user@jakarta.apache.org Received: (qmail 22392 invoked by uid 97); 7 Feb 2002 00:55:45 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Users List" Reply-To: "Tomcat Users List" Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 22381 invoked from network); 7 Feb 2002 00:55:45 -0000 Date: Wed, 06 Feb 2002 19:55:40 -0500 From: gilmoresp@netscape.net To: tomcat-user@jakarta.apache.org Subject: Multi-user problem Message-ID: <35E77B3C.7D5ECA76.03035E8E@netscape.net> X-Mailer: Atlas Mailer 1.0 Content-Type: text/plain; charset=iso-8859-1 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N "Tom Drake" wrote: As suggested, I will try to find a different driver (instead of the odbc/jdbc bridge) to connect to MSSQL2k. In the meantime.. I reflect on your other thoughts... >>See my comments below. >... snip ... >| >| The NEXTIMAGE servlet looks something like this pseudo-code: >| public static void login(...){ Tell database user is logged in. } >| public static void logout(...) {Tell database user is logged out.} >| public static void updateaccesstime(...) {Tell Database I made a request} >Are the above functions keeping class data >(such as a connection to your database)? > >If a 'login' request gets a new database connection, >then any other thread that is using >the original connection will break. Do other instances of the servlet count as other threads? I'm not sure I understand what you mean by "keeping class data", so I've copied the 3 methods here. In an attempt to answer your question... 1) None of my servlets use multithreading.. I'm new to Java and haven't learned that yet. 2) A database connection is opened as soon as necessary in the servlet and I expect it to remain available until the servlet closes. I do not expect it to be available across multiple instances. 3) The database connection is forced closed at the end of the servlet. Here's the code for the 3 routines plus the database connect and disconnect (please don't laugh.. this is the result of a very steep learning curve and a bunch of troubleshooting). As you see, the login/out methods expect an existing statement (which is bound to a connection) as a parameter: //--------------------------------------------------- public static void login(String userid, Statement st) { String s=""; System.err.println("Login"); try { s= "use sqaa "+ "update emps "+ "set loggedin=1, "+ "lastaccess='"+thelper.getcurtime()+"' "+ "where userid='"+userid+"' "; st.executeUpdate(s); } catch (Exception exc) { System.err.println("Error during login()."); System.err.println(" "+exc.getClass().getName()); System.err.println(" "+exc.getMessage()); System.err.println(s); return; } } //------------------------------------------------------------ public static void logout(int userrecordid, String userid, Statement st) { String s=""; System.err.println("Logout"); try { System.err.println("..logging out"); s= "use sqaa "+ "update emps "+ "set loggedin=0 "+ "where userid='"+userid+"' "; st.executeUpdate(s); System.err.println("..cancelling reservations for "+userrecordid+", "+userid); s= "use sqaa "+ "update images "+ "set auditorid=null, auditorstatus='U' "+ "where auditorid="+userrecordid+" "+ "and auditorstatus='X'"; st.executeUpdate(s); System.err.println("Done logging out."); } catch (Exception exc) { System.err.println("Error during logout."); System.err.println(" "+exc.getClass().getName()); System.err.println(" "+exc.getMessage()); System.err.println(s); return; } } //------------------------------------------------------------ public static void updateaccesstime(String userid, Statement st) { String s=""; System.err.println("Updateaccesstime"); s= "use sqaa "+ "update emps "+ "set lastaccess = '"+thelper.getcurtime()+"' "+ "where userid='"+userid+"' "; try { st.executeUpdate(s); } catch (Exception exc) { System.err.println("Error during updateaccesstime()."); System.err.println(" "+exc.getClass().getName()); System.err.println(" "+exc.getMessage()); System.err.println(s); return; } } //Open JDBC Connection (This occurs right after getting the POST parameters): try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:sqaa","philg",""); query = con.createStatement(); } catch (Exception exc) { System.err.println("Error creating JDBC connection."); System.err.println(exc.getClass().getName()); System.err.println(exc.getMessage()); thelper.fileServe(out,"c:/html/except.html"); return; } //Close database connection (this is the last thing done). try{ con.close(); } catch (Exception exc) { System.err.println("Error closing database."); System.err.println(exc.getClass().getName()); System.err.println(exc.getMessage()); thelper.fileServe(out,"c:/html/except.html"); return; } -- __________________________________________________________________ Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience of buying online with Shop@Netscape! http://shopnow.netscape.com/ Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/ -- To unsubscribe: For additional commands: Troubles with the list: