File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes JSP and connection with Database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "JSP and connection with Database" Watch "JSP and connection with Database" New topic

JSP and connection with Database

Ramesh Subramanian

Joined: Oct 03, 2000
Posts: 13

How to connect Applet-JSP-Database?
Can any one pl tell me with example code? or tell me the site from which i can get more idea about this?
Thanks in Advance,
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Hi Ramesh,
You would find lots of information on how to connect the Applet/JSP/Servlet to the Database in various books available in the market.You may refer to Pure JSP By James Goodwill for some examples.
There is nothing tricky about this.You can access DB using the usual JDBC steps, viz. creating a connection, creating a statement,creating a resultset and iterating through it.
If you are using the Applet-Servlet-DB architecture, write the JDBC code in the Servlet and that too in the init() (or I suggest you use Connection Pooling..Pure JSP has an example for it) for performance benefits.
If you are using the Applet-JSP-DB architecture, write the JDBC code in the JSP.You may consider writing the JDBC calls in the JavaBean and create an instance of the bean using the <jsp:usebean> tag.
Hope this helps.
Sandeep Desai

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56

  5. [This message has been edited by Desai Sandeep (edited April 25, 2001).]
Santosh Jaiswal

Joined: Oct 04, 2000
Posts: 26
Can you please tell me which one is better?
Applet-Servlet-DB architecture or Applet- JSP - architecure
Andrew Shafer
Ranch Hand

Joined: Jan 19, 2001
Posts: 338

JSP's are compiled into servlets so these are functionally equivalent.
Assuming your applet takes care of the view, you might see some performance benefit with pure servlets in some applications.

I agree. Here's the link:
subject: JSP and connection with Database
It's not a secret anymore!