• Post Reply Bookmark Topic Watch Topic
  • New Topic

best way to connect to a database from jsp  RSS feed

 
Arun Kumar
Ranch Hand
Posts: 135
Chrome Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the best way to connect to a database from jsp? I know i shouldnt be making databse connections from jsp .but in the last two interviews i attended they asked me how do you connect to databse from jsp

I know I have to use a scriplet , javabean or jstl for the purpose but what is the best way
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is wise to separate the data access code (part of the model) from the code that presents the data (view). Read about the MVC design pattern for more info.

In general, the best way to access a database is to use a Data Access Object. The DAO would be called from the controller servlet and the resulting data passed to the JSP as a bean.

If you must to do it from a JSP, you could use the JSTL database tag library. But this isn't a best practice for the reason stated above.
[ September 07, 2006: Message edited by: Scott Johnson ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a trick question. If I were to ask it and you gave any other answer than "you shouldn't", the interview would be a short one.
 
Joshua Cloch
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try to use "connection pool" which may bring huge advantage.

whether to connect your database from JSP depends on your project scale, if that is small one, just use JSTL, which is agile and efficent;otherwise, you may need to delve further from the replies shown above
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!