December 30th, 2002, 12:47 AM
Ok, I'm writing a Content Management System for an upcoming website, and I am currently working on writing classes for doing database access, more specifically, loading and saving user information.
What i have now is a class User, which contains a users username, password, and userid.
3 different constructors allow it to be instantiated using a username, userid, or a blank object for creating a new user. Also passed into the constructor is a Connection object, which is the database connection being used for the Entity Object. This allows the objects save and load methods to access the database without actually setting up the connection within the class.
My biggest question is, is that a good way of doing this? I think it will make the code in my jsp pages and servlets much easier to read, as well as cut down on redundant code, because all the mundane and messy operations which are used alot are kept hidden for the most part.
December 30th, 2002, 06:16 AM
That doesn't sound too bad.
Have you looked into connection pooling at all? It's way more efficient, and kind of takes care of what you're trying to accomplish. Some app servers can set up connection pools for you (more efficient that way), or you can create them yourself. Basically, this gives you a single class that manages all your connections, then you just grab a connection when you need it, and return it to the pool when you're done. It removes the overhead of making a fresh connection each time, plus it allows for multiple connections (you decide how many), to be made simultaneously. Your app will be faster for multiple users that way.
December 30th, 2002, 09:54 AM
Oooh, That sounds cool, dyou have a link to a tutorial for setting that up?
December 30th, 2002, 04:02 PM