Quoth Sam Rose:
> I'm trying to create a servlet that allows a user to log in to a
> database. [snip]
> I am trying to do it is by having just one servlet/java code take
> in the username and password and then this would be called by every > servlet that
>needed to connect to the database.
Sigh. OK, what you *really* want to do is get a book about servlet
programming, and probably one about Java/JDBC programming as well. I
can wholeheartedly recommend Jason Hunter's book for the former, and
there are more of the latter available than you can shake a mouse at.
That said, what you're going to want to do is *not* have different
servlets access this one database holding servlet. If you want a one
connection per user model, the best way to do this is by storing the
database connection (as opposed to the login and password, which
themselves can only be used to generate a connection) inside an
HttpSession object, thus:
HttpSession s = request.getSession(true); // create the session if
doesn't exist
String login = request.getParameter("login");
String password = request.getParameter("password");
DBConnection db = new DBConnection(login, password); // use your own
database connection constructor here...
s.putValue("db", db); // now it's available to other servlets with
getValue("db")
If you *really* want one connection regardless of the number of
users/processes, store the db object in the servlet's system properties
list...
--
Within C++ is a smaller, cleaner language
struggling to get out.
It's called Java.
Thomas Moore
[EMAIL PROTECTED] Home Account
Software.Engineer [EMAIL PROTECTED]
phone://732.462.1880:268 NJ Patterns Group Home Page
employer://Celwave, RF http://members.home.net/twmoore/cjpg
___________________________________________________________________________
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