This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP & JDBC implementation question" Watch "JSP & JDBC implementation question" New topic
Author

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.
WS


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

Joined: Jan 10, 2002
Posts: 61066
    
  66

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.
hth,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP & JDBC implementation question