How to Connect MySQL from JSP Page

Thread Solved

Join Date: May 2008
Posts: 6
Reputation: ashish1234 is an unknown quantity at this point 
Solved Threads: 1
ashish1234 ashish1234 is offline Offline
Newbie Poster

Re: How to Connect MySQL from JSP Page

 
-1
  #31
May 29th, 2008
Can u plz tell me wats wrong in using jsp to connect to a databse..
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 36
Reputation: electron33 is an unknown quantity at this point 
Solved Threads: 4
electron33 electron33 is offline Offline
Light Poster

Re: How to Connect MySQL from JSP Page

 
0
  #32
May 29th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,260
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 493
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: How to Connect MySQL from JSP Page

 
0
  #33
May 29th, 2008
Originally Posted by electron33 View Post
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
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 36
Reputation: electron33 is an unknown quantity at this point 
Solved Threads: 4
electron33 electron33 is offline Offline
Light Poster

Re: How to Connect MySQL from JSP Page

 
0
  #34
May 30th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 36
Reputation: electron33 is an unknown quantity at this point 
Solved Threads: 4
electron33 electron33 is offline Offline
Light Poster
 
0
  #35
Oct 27th, 2009
Originally Posted by ashish1234 View Post
Can u plz tell me wats wrong in using jsp to connect to a databse..
Do you have some source code?
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,467
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 267
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven
 
1
  #36
Oct 27th, 2009
Originally Posted by electron33 View Post
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.

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.

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.

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.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 22227 | Replies: 35
Thread Tools Search this Thread



Tag cloud for JSP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC