• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp and jdbc

 
viral patel
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can i excute multiple query in jsp page to fill database. If i can, can you give me example of it.
thanks
 
Andy Bowes
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In short there are many ways of executing SQL queries against the DB from the JSPs however in short there should be NO direct link between the database layer and the presentation tier.
Separate your application out into 3 distinct layers Presentation, Control/Business, and Persistence ( more commonly known as Model View Controller orMVC). Only put code that accesses the database in the Persistence layer. The Control layer is responsible for receiving the requests from the Presentation layer i.e. the JSPs and then calling the appropriate objects/methods in the Persistence tier.
This separation of concerns makes the application much more maintainable i.e. you can change the DB structure without needing to rewrite the all of the JSPs in the application.
In EJB terms the Presentation tier will be JSPs, the Control/Business tier will be a combination of servlets and Session Beans and the Persistence layer will be Entity Beans. This same tiered approach can also be acheived perfectly well without EJBs by using the Data Access Object patterns to encapsulate the interactions with the DB
 
Peter Daly
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While Andy is right that you really should not directly access a database from JSP's from an architecture, it doesn't mean it can't be done.
A JSP can execute java code just like a normal java object, and more than one sql update can be run the same way it can me done in Java.
get a connection and statement object then:
stmt.executeUpdate("INSERT SQL1...");
stmt.executeUpdate("INSERT SQL2...");
stmt.executeUpdate("INSERT SQL3...");
stmt.close();
conn.close();
-Pete
Computer Books
[ March 13, 2003: Message edited by: Peter Daly ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic