tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jason Koeninger" <jkoe...@jjcc.com>
Subject Re: Multi-user problem
Date Thu, 07 Feb 2002 02:35:39 GMT
On Wed, 06 Feb 2002 19:55:40 -0500, gilmoresp@netscape.net wrote:

>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...

Is "con" a class variable?  For instance, is it declared something like this:

public class MyServlet extends HttpServlet {

	private Connection con;
	.
	.
	.
};


If it is, multiple users will step on each others' connections.  Only one instance 
of the servlet is created to serve multiple requests.  If "con" is declared local 
to the service method, then it's not a problem.

Best Regards,

Jason Koeninger
J&J Computer Consulting
http://www.jjcc.com



>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:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
>For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
>Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>
>




--
To unsubscribe:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>


Mime
View raw message