Best way to access RDBMS
Hi,
I find that there are many ways to access databases in a JSP.
1. Using scriptlets <%%>
2. Using DataSource (I could not understand this. Please provide me some link which gives a basic tutorial of this scheme)
3. Using a separate Java bean/class to retrieve data from DB.
Which of these schemes is the best to use for web applications? How exactly does DataSource work?
[416 byte] By [
chasana] at [2007-11-27 0:57:58]

# 3
>I find that there are many ways to access databases in a JSP.
>1. Using scriptlets <% %>
A very bad bad pratices as far as maintainace is concern you would endup writing Kilo Lines of code and would be a herculian task if someone replaces your position in the maintainance / testing phase
>2. Using DataSource (I could not understand this. Please provide me some link which gives a basic tutorial of this scheme)
As far as Datasource is concern read the below article which gives you very gud idea about what it is,how to use it..etc
http://java.sun.com/j2se/1.4.2/docs/guide/jdbc/getstart/datasource.html
>3. Using a separate Java bean/class to retrieve data from DB.
Well you would create multiple of similar instances for the sake increasing the load on container.
Well I kind of Support wat my fellow poster(above me) said...
I think it should something Like this
JSP,View Beans (View)
|
|
|
Controller(Webtier under Web-Container)
|
|
|
BeanFactory (MODEL / Business Tier could be EJB / IoC [Spring] Containers)
|
|
|
|
ORM(DBAccess)
(Layer could be COAD,Hibernate,JDO,Persitant Beans,Toplink or custom built Architecture by yourself using the Datasource configured by you)
Most of the people prefer each of these layers to be loosely coupled & prefer each one them to run independently.
and most of the people prefer using singleton/prototype instantions effectively which reduces load on the containers too.
However, there are many other practises where this can change as per requirements....
and a small advice please always use J2EE Patterns & Best Pratices for devolping a better design..
Hope this might help :)
N'joy coding...
REGARDS,
RaHuL