Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP and Database connections  RSS feed

 
Tomas Nilson
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Stanley Tan
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What will be the problems if i don't use connection pool.. pls tell me the points..
Pranit..
 
Tomas Nilson
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Eric Peterson
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!