944,044 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Marked Solved
  • Views: 39115
  • JSP RSS
You are currently viewing page 4 of this multi-page discussion thread; Jump to the first page
May 29th, 2008
-1

Re: How to Connect MySQL from JSP Page

Can u plz tell me wats wrong in using jsp to connect to a databse..
Reputation Points: 8
Solved Threads: 1
Newbie Poster
ashish1234 is offline Offline
6 posts
since May 2008
May 29th, 2008
0

Re: How to Connect MySQL from JSP Page

There is nothing wrong by putting the database connection in the JSP, but you have to create a new database connection and query for every page you creates. This will reduse the performance and response on server. This is one of the problems. Instead you could create a connection class and put it into application scope and the connection will be made when server is started. This is done only once. Then it is available for all objects that uses table info from the database.
Last edited by electron33; May 29th, 2008 at 8:28 pm.
Reputation Points: 30
Solved Threads: 4
Light Poster
electron33 is offline Offline
36 posts
since Jan 2008
May 29th, 2008
0

Re: How to Connect MySQL from JSP Page

Click to Expand / Collapse  Quote originally posted by electron33 ...
There is nothing wrong by putting the database connection in the JSP
Ever heard of MVC (Model-View-Controller)? Well then you may want to google out something on the subject and learn new things
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 874
Code tags enforcer
peter_budo is offline Offline
6,658 posts
since Dec 2004
May 30th, 2008
0

Re: How to Connect MySQL from JSP Page

MVC (Model View Controller) That is Model this part holds the data between view and database or files, View this is the JSP, GUI or other interface presentet to the user, Controller this is the part that sends the messages of what to do with the data when user clicks a component or some changes happens on the database table. Please read more about this topic at SUN's pages.
Reputation Points: 30
Solved Threads: 4
Light Poster
electron33 is offline Offline
36 posts
since Jan 2008
Oct 27th, 2009
0
Re: How to Connect MySQL from JSP Page
Click to Expand / Collapse  Quote originally posted by ashish1234 ...
Can u plz tell me wats wrong in using jsp to connect to a databse..
Do you have some source code?
Reputation Points: 30
Solved Threads: 4
Light Poster
electron33 is offline Offline
36 posts
since Jan 2008
Oct 27th, 2009
1
Re: How to Connect MySQL from JSP Page
Click to Expand / Collapse  Quote originally posted by electron33 ...
There is nothing wrong by putting the database connection in the JSP,
Yes there is. You have obviously never worked on anything that lasted more than a few days, or ever needed to be expanded or improved or fixed. Scriptlets are a maintenance nightmare. At the very least use a bean.

Quote ...
but you have to create a new database connection and query for every page you creates.
Hopefully you mean retreiving one from a Connection pool and not actually creating one with every query. That would be a performance nightmare.

Quote ...
This will reduse the performance and response on server. This is one of the problems.
(I guess you didnt mean using a pool.) Not with a Connection Pool, and every web container (which you must be using to use JSP) has a connection pool, so no problem.

Quote ...
Instead you could create a connection class and put it into application scope and the connection will be made when server is started. This is done only once. Then it is available for all objects that uses table info from the database.
Yet another bad suggestion. A static, single connection used by a dynamic (God I hate that word) threaded application? What happens when one thread calls rollback directly before another thread was about call commit? Or the other way around?


Connection Pools, Beans, and a properly implemented layered approach. Everything presented here is ....... well, I don't think I really need to say it.
Last edited by masijade; Oct 27th, 2009 at 5:42 pm.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: Unable to connect to tomcat through browser
Next Thread in JSP Forum Timeline: MVC help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC