File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes JSP and Database connections Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "JSP and Database connections" Watch "JSP and Database connections" New topic
Author

JSP and Database connections

Tomas Nilson
Ranch Hand

Joined: Jan 14, 2002
Posts: 33
Hello group!
I am developing a system using JSP, Java Beans and a MySQL database.
The Bean talks to the database, and I was wondering what the best way is to set up the connections to the db?
I was also wondering if anyone knows what happens when two people access the same jsp page at the same time - do they get to separate instances of the bean?? Will this cause any problems for my bean in regards to having two requests using the same connection simultaneously?
Thanks a lot!
/Tomas
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12265
    
    1
The best way to set up connections is with a connection pool.
The number of users sharing a JavaBean depends on the scope you assign the bean in the useBean tag. The choices are page, request, session and application.
Bill


Java Resources at www.wbrogden.com
Stanley Tan
Ranch Hand

Joined: May 17, 2001
Posts: 243
I agree. Use a connection pool, which should be handled transparently, so you don't have to do much. Also, each user should get a separate bean as long as the scope isn't application.
Pranit Saha
Ranch Hand

Joined: Sep 09, 2001
Posts: 130
What will be the problems if i don't use connection pool.. pls tell me the points..
Pranit..
Tomas Nilson
Ranch Hand

Joined: Jan 14, 2002
Posts: 33
Thank you all for your answers!
>What will be the problems if i don't use connection pool.. pls tell me the points..
You have to be careful so you don't have two users using the same connection simultaneously (that was my main concern, and this could happen if you do it the wrong way). But the biggest pro with connection pooling is efficiency as you don't have to create a new connection for every request - you simply reuse them from the pool.
Hope this is correct,
Tomas
sripad devaraju
Greenhorn

Joined: Nov 26, 2001
Posts: 5
Hi,
any body can sujest good resource, where can i find good and nice explanation about implimentation of Connection Pooling using JSP.
I am using Professional JSP from WROX publications
regards
sripad


shippu
Eric Peterson
Ranch Hand

Joined: Jan 08, 2002
Posts: 31
Sripad,
I can suggest a very good book called Core Servlets and Java Server Pages by Marty Hall. Their is a website for the book at Core JSP and their is also source code from the chapter on database connection pooling at Jsp/servlet code. I hope this helps and best of luck.


Eric Peterson
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: JSP and Database connections
 
Similar Threads
Connection pooling vs using a single connection
Need Help on IllegalStateException
Multiple DataSources
Running out of database connections using JSP
ReadTimeOut Problem in Tomcat4