• Post Reply Bookmark Topic Watch Topic
  • New Topic

Database Connectivity using JSP or Servlet?

 
Vivek K Jain
Greenhorn
Posts: 19
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to know which way is secure and efficient.I am working on a project for designing grievance redressal system.I need to connect to database for fetching results and displaying them in a view jsp in form of a table..so should i connect using <sql> tags dataSource or fetch result in servlet and use it in jsp using setAttribute method.
in both case please provide the way for doing so.
my main concern using
JSP is do the connection closes by <sql> tags..and if i use servlet how to store resultset with different column and multiple rows that need to be displayed ina table in jsp..
please explain in some details
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neither. In a properly structured web application, database connectivity will be completely hidden from the UI layers by the model.

But even if you insist on following non-best practices, you should not use the JSTL SQL tags in production code. The JSTL Specification even warns against this.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lucky soni, your post was moved to a new topic. Please be sure to start new topics fro your own questions.
 
Vivek K Jain
Greenhorn
Posts: 19
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i agree sql update don't have any significance for displaying web content but then <sql:query> can be used to retrieve data required to display on the web(in form of a table), otherwise how will i accomplish that as the table is dynamic and generated through contents from database.
Secondly you mentioned that neither of jsp or servlet should be choosen for database driver loading and connecting, then please suggest me where to do so. i use to do that in each servlet wherever required.
I have heard that setting up JNDI datasource wont expose login information ..if yes then please explain that way also.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vivek forHf wrote:i agree sql update don't have any significance for displaying web content but then <sql:query> can be used to retrieve data required to display on the web(in form of a table), otherwise how will i accomplish that as the table is dynamic and generated through contents from database.

Your model classes should abstract where this data comes from. The UI should not know where the list comes from, just that it gets the list to display.

Secondly you mentioned that neither of jsp or servlet should be choosen for database driver loading and connecting, then please suggest me where to do so.

The model. JSP is for the View layer, servlets for the Control. Neither should be performing database actions. That's the role of the Model.

i use to do that in each servlet wherever required.

That is considered a poor practice.

I have heard that setting up JNDI datasource wont expose login information ..if yes then please explain that way also.

That is an excellent way to make the DB information available to the model. It also allows you to easily use container-managed connection pooling, which is a very good thing to do.

Setting this up is dependent upon which container you are using. If it's Tomcat, see the Tomcat forum for previous discussions of this topic, and the Tomcat documentation itself.

If you are using something else, consult its documentation.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!