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]
# 1
3. Using a separate Java bean/class to retrieve data from DB.have a seperate class to establish connect to DB when you initially open your app.Create BO, TO objects as per your needs.This is best way, I guess.
skp71a at 2007-7-11 23:31:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
JSP should sit in the presentation logic.DB access should sit in the persistent logic.JSP <-> Servlet <-> Business Logic <-> EJB <-> DB
rym82a at 2007-7-11 23:31:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 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

RahulSharnaa at 2007-7-11 23:31:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Thanx guys, EJBs can't be used as I'd be running the project on Tomcat alone. So, I think I'd go with JSTL, data access tags.
chasana at 2007-7-11 23:31:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
If you can't use EJB, you can develop your own DAO or whatever you like.It just a matter of taste, but i think a better MVC model would make your application easier to maintain.
rym82a at 2007-7-11 23:31:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...