aspose file tools*
The moose likes JSP and the fly likes Are there alternatives to JSTL and scriptlet database connection? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Are there alternatives to JSTL and scriptlet database connection?" Watch "Are there alternatives to JSTL and scriptlet database connection?" New topic
Author

Are there alternatives to JSTL and scriptlet database connection?

Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 746
Hi guys!

The situation:


I'm doing an inventory system. I am using struts framework with JSTL. I need to populate a dropdown menu(<select> or <html:select for struts> ;) but I'm thinking of how I would access the database... If I access the database using the following tags



The problem:

1. My database connection would be tied up with my code and it would be hard to maintain the system if I wanted to change my database in the future... I will always have to get access to the source code...

2. This one is specific to JSTL... Using the following tags...



I don't have any idea how I would get each column in every row... I need to...


<html ption value="PUT DEPARTMENT_ID HERE">DEPARTMENT_NAME HERE</html ption>

You have any idea guys? It would really be a great help... Thanks!

[Bear edit: removed "urgent" from title]

[ January 13, 2006: Message edited by: Bear Bibeault ]
[ January 13, 2006: Message edited by: Timothy Sam ]

SCJP 1.5
http://devpinoy.org/blogs/lamia/ - http://everypesocounts.com/
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

First steps:

1) Read this

2) read this

3) Modify your topic title to something meaningful

4) Always check the 'disable smilies' checkbox when posting code so that your tags look less surprised.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

My advice is to never do SQL in the JSPs, even with the JSTL SQL tags (which are not intended for production code).

By segregating your database access into a model layer, you achieve many benefits, not the least of which will be the simplification of your front-end code.
Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 746
sorry dude... I will do that next time... Thanks for your advice! Now where is that change topic button...
Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 746
I found a solution on the internet for question number 2... I haven't tested it yet but it goes like this...


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

Originally posted by Timothy Sam:
Now where is that change topic button...


Click on your first post.
Thibault Dangr�aux
Greenhorn

Joined: Dec 12, 2005
Posts: 19
I second Bear. Implement a DAO, and eventually a service pattern.
Your controller (well, action since you're using Struts) will query that DAO (or service) and store the result list as a request attribute. Then, your JSP will render that list in whatever HTML form you pick, without worrying about where that data came from.
That way, you have proper MVC separation. If you decide to get your data from another source (hibernate rather than straight SQL, XML service, static collection for debugging...), you just have to touch your service (or DAO) layer without impacting anything else.
Saket Barve
Ranch Hand

Joined: Dec 19, 2002
Posts: 229
sorry dude...


It is not often that one gets to see Bear addressed thus!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Are there alternatives to JSTL and scriptlet database connection?