Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to strutcture a jsp app that uses mysql  RSS feed

 
Christopher Whu
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am building an online store... I know how to get the data from the mysql but i am wondering where i should put my query code..

I am going to make a product class, should i be putting the query statements in there... Is there an article that shows some basic structure on how to set this up...

Should i make a dbBroker class and just put the query code in there...

I know there are tons of ways to do this, just wondering how working programmers do it, lol...

thanks in advance...
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66144
143
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Database access should be sequestered away in the model layer, as far from the JSPs and presentation layer as possible.
 
Christopher Whu
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ty for getting back so quick...

i was thinking about a separate class from my product class to handle grabbing all the data from mysql..

Is this amateurish?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66144
143
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you read up on the MVC pattern?
 
Christopher Whu
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have read about it in my Java books and school... I will brush up and try to apply it to my data...

is there a good online article about MVC that you would recommend...

TY again...
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66144
143
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This article might be helpful to start.
 
Christopher Whu
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Awesome article Bear... I am definitely going to try and use alot of that in the application...

Are there any books that you would recommend for using MVC 2 with java?
 
Christopher Whu
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what i ended up doing was creating a class called DBBOSS whose methods return the info from the database that i need... I did not have the guts to go jsf on the app because of the project deadline and not working with JSF...

i bought CORE JSF and i have been studying it on my own time to get ready for my next project.

i did however use the model chapter a bit to kind of create a data model that creates and modifies arrays attached to a shopping cart object. My browse products JSP runs off the model. I even added some ajax to the page that listens for changes in <SELECT> and then shoots instrux to a servlet which modifies the model. When the servlet sends back the changes to ajax, i refresh the page (the page fetches the new arrays and renders nicely...

Ty for the help bear, you pushed me in a good direction... I have since even joined the icefaces community and listened to some of there webinars.
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use like:

JSP ---> Servlet ---> Facade ----> Database.

I know this is pretty simple, but it is just to give you an idea. [=
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!