aspose file tools*
The moose likes Struts and the fly likes Retreving data from Database and display on using JSTL. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Retreving data from Database and display on using JSTL." Watch "Retreving data from Database and display on using JSTL." New topic
Author

Retreving data from Database and display on using JSTL.

komal ekbote
Greenhorn

Joined: Jun 20, 2007
Posts: 17
Can Anyone please tell me how to retrive data from database and display on JSP usin the JSTL tags.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Although JSTL has an "sql" library that will perform various database operations, it is recommended only for prototyping, and not for real production applications. If you want to learn how to use them, though, this is a good article.

The best practice for accessing a database in a web application is to create model classes in the form of JavaBeans that represent the data upon which your application is based. For example an HR application you'd have classes like Employee, Department, Address, Company, etc. You'd also create other classes with methods that will translate the above objects to and from rows and columns in the database. For example, you might have an EmployeeDAO class with a method getEmployeesByDepartment(String dept) that would return a collection of Employee objects.

Another option would be to use an object relational mapping tool such as Hibernate that handles writing the underlying SQL statements for you.

Once you have these model objects either in collections or as individual instances, you can then use jstl tags like c:forEach and cut to iterate through collections of these model objects and display their properties.
[ October 23, 2007: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
komal ekbote
Greenhorn

Joined: Jun 20, 2007
Posts: 17
Thank you Merill.
Tarun Yadav
Ranch Hand

Joined: Sep 20, 2007
Posts: 134
Have a look at these:

[1] http://java.sun.com/docs/books/tutorial/jdbc/
[2] http://www.oracle.com/technology/sample_code/tech/java/codesnippet/jsps/jstlsql.html
[3] http://www.ibm.com/developerworks/java/library/j-jstl0520/

EDIT: Sorry, was a bit slow there.
[ October 23, 2007: Message edited by: Tarun Yadav ]
 
 
subject: Retreving data from Database and display on using JSTL.