First, if I need to be on a different list, please let me know. I'm 
working my way up from Tomcat, which is where the servlet I'm 
developing is going to be running. I'm a Java newbie, but I'm on this 
project, and the learning curve is steep. Sadly, Google hasn't been my 
friend this time - I'm finding conflicting information and so I 
searched out a mailing list to ask....

I've got Tomcat 5.5.12 running on my Win XP SP2 machine. I'm 
developing against that for now. I'm working on a servlet that will be 
accessing a MySQL database, so I've grabbed Connector/J from the MySQL 
site, and followed their info, plus the Tomcat JNDI Datasource How-To 
on settting up a context.xml for my database.

And that all works. I used the sample JSP from the Datasource How-To 
and was able to access my database.

My issues start when I work on my servlet. The basic tutorials and 
examples show something simple all happening within the one 
MyServlet.java file - create the JDBC context, set up a DataSource, 
get a Connection, and work with some Statements. Everything in one 
class implementing the servlet. When things get a little more 
complicated (read that as "when you want to do things in the real 
world"), then the examples disappear and some handwaving seems to 
replace it. That's becoming very confusing, particularly when this is 
the first real Java project you've worked on.

In my case, I want to have some different classes to read and write my 
database. Basically, there's one class for handling data coming in, 
and a second class to handle data going out. Based on what I've read, 
I want to use the "connection pooling" that's already present in the 
Commons DBCP that's included with my Tomcat installation. However, 
establishing contexts is "expensive" in terms of performance (again, 
so I've read), so I want to just use the DataSource I have set up in 
my context.xml. So more Googling, more reading, and I ran across some 
examples of Connection Pools that use a "Singleton Pattern". Only I 
thought I already had a connection pool, and I'm trying to figure out 
how to make my design share the DataSource I was setting up in my 
servlet init() method, because I thought that would help my servlet's 
performance.

Am I way off-base here? Is there an example that shows how this type 
of thing should be designed? Should I just duplicate the 
Context/DataSource/Connection/Statement stuff in all my classes? Or is 
that the wrong way?

I could always configure my classes to have a DataSource passed in 
from the doGet() or doPost() handlers, but that doesn't seem like the 
right approach. I may do that just to get something working, but I 
hate learning how to do things the wrong way...

Thanks in advance for any pointers you can provide...

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to