• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Are there alternatives to JSTL and scriptlet database connection?

 
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 751
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry dude... I will do that next time... Thanks for your advice! Now where is that change topic button...
 
Timothy Sam
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found a solution on the internet for question number 2... I haven't tested it yet but it goes like this...


 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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



Click on your first post.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sorry dude...



It is not often that one gets to see Bear addressed thus!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic