The moose likes JSP and the fly likes JSP & JDBC implementation question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP & JDBC implementation question" Watch "JSP & JDBC implementation question" New topic

JSP & JDBC implementation question

Winston Smith
Ranch Hand

Joined: Jun 06, 2003
Posts: 136
Hello All,
Currently I'm using JSP scriptlets to establish connectivity with a database (with all variables declared within a JSP page). This database will be accessed from a number of pages. I'm thinking about using a bean (with application scope) to establish a connection and store all necessary variables. This way, I can use the bean (and the database connection) by simply accessing the Connection variable. First, is there a fault in my logic here (I'm new to JSP)? Second, which would be a better implementation (in regards to security/efficiency):
1.) a bean as described above
2.) a JSP page with all necessary variables and database functions (sort of like a header file)
You guys are great. Thanks for any help/suggestions you can offer.

for (int i = today; i < endOfTime; i++) { code(); }
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

A JSP page would be the worst possible choice for something like this. You should strive to keep your JSPs as purely display oriented as possible, and factor out processing -- such as database access -- into other Java elements.
Of the two choices you gave, the bean approach is vastly superior. However, you could do even better and abstract your data layer completely from the UI.
I'd suggest that you search these forums for the terms "MVC" and "model 2". A lot of good information on structuring web applications is to be had.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: JSP & JDBC implementation question
It's not a secret anymore!