aspose file tools*
The moose likes Servlets and the fly likes on servlets and jdbc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "on servlets and jdbc" Watch "on servlets and jdbc" New topic
Author

on servlets and jdbc

pratap kumar
Greenhorn

Joined: Nov 09, 2000
Posts: 2
hai,
1.when u create a connection to database for e-mail services
how many connection objects are created?
can i establish the connection in init()method or service()method ?
2.with loading one driver can i establish different connection
with diff database. is it possible pl give the code also?
thanku
by
pratap
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
I'm not really sure what you are asking. You may find it useful to ask again in different words.
1. Databases have very little to do with e-mail. When you create a database connection through JDBC, you get a single connection to the specified database.
Whether you establish the connection in the init() method or the service() method depends on both the database driver and the way your servlet is to be used. If your database driver allows connections to be opened and left open for long periods, it may be feasible to open the connection in init(). If opening a connection is quick (say if you are using an in-VM database like InstantDB or HypersonicSQL) it may be better to open a connection each time in the service() method.
In general, the best method is to use a Connection Pool, which you initialize in the init(), and then request a connection from it in each service() call. The pool should take care of connections which are "timed-out" by the database driver, and create connections as necessary.
2. You can create several different database connections with most database drivers. You load the driver once, but create as many connections as you like, specifying the same driver, but different database, user and password.
I hope this has helped.
2.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: on servlets and jdbc