• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlets with JDBC

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Raghu Kumar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic