aspose file tools*
The moose likes Servlets and the fly likes Servlets with JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets with JDBC" Watch "Servlets with JDBC" New topic
Author

Servlets with JDBC

Raghu Kumar
Greenhorn

Joined: Jan 08, 2001
Posts: 9
Hi All,
i have a small doubt regarding JDBC with servlets.
suppose assume that i have 3 html's( called using servlets). main page which takes care of logging in, second page is to retrieve and display data from database and third page is to enter data. So if i create a connection object,statement object if the user is valid in the first page can i use the same objects in the second and third html pages(servlets)? If so what should i do? Do i need to declare these objects to be static or is there any other way to handle this? Hope my question is clear?
Cheer's,
Raghu
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
This sort of problem is precisely why the concept of "sessions" was invented. Look up HttpSession in your servlet books/websites, and you should find lots of examples of gathering or chacking information in one servlet and using it in another.
Even if your pages are generated by a single servlet (not usually a good idea, unless you delegate to other classes or templates), you should still store your information in the session to make sure that your system still works when more than one person tries to access it at once.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Raghu Kumar
Greenhorn

Joined: Jan 08, 2001
Posts: 9
Thanks for the reply Frank. I am not using the same servlet for all the three pages. i am using three servlets for each three html pages. so i mean to say that in this case can i access the object's of one servlet in another servlet?
Originally posted by Frank Carver:
This sort of problem is precisely why the concept of "sessions" was invented. Look up HttpSession in your servlet books/websites, and you should find lots of examples of gathering or chacking information in one servlet and using it in another.
Even if your pages are generated by a single servlet (not usually a good idea, unless you delegate to other classes or templates), you should still store your information in the session to make sure that your system still works when more than one person tries to access it at once.

Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Yes. You may put any objects into the session. It's like a Map, and once a session is created you may put objects in and retrieve them by name from any cooperating servlet.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlets with JDBC