Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retreving data from Database and display on using JSTL.

 
komal ekbote
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can Anyone please tell me how to retrive data from database and display on JSP usin the JSTL tags.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
komal ekbote
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Merill.
 
Tarun Yadav
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic