Hi, This is to answer your question >what is the difference between the 2 solutions? Init has alomost the same functionality of the constructor in that it is called before the servlet handles its first request. The difference between the constructor and the init method is as follows. 1)in jdk1.0, constructors of dynamically loaded classes (servlets too fall in the category of dynamically loaded classes) cannot accept accept arguments. So, in order that the server can pass information to the servlet regarding its environment, a new method , init(ServletConfig) had to be defined. 2)Java interfaces cannot declare constructors. So, since the javax.servlet.Servlet interface too cannot declare a constructor which accepts arguments, a new mehtod init had to be defined. Therefore, the init method is typically used to perform servlet initiliasation. In a constructor you don't have access to the ServletConfig Object. Neither can you throw a Servlet Exception in a constructor. This should answer your second Question > how to inform the client in case of DB connection failure? You can catch the SQLException in the init method and then throw a servlet Exception. Hope this explanation helps. Venita ___________________________ On Mon, 22 May 2000 15:25:45 Xu Jianwu wrote: >I've tried the solution of overriding the construction method and it seems >working. Overriding init() sounds more reasonable since the construction >method of Servlet does nothing. But what is the difference between the 2 >solutions? Even for overriding init(), how to inform the client in case of >DB connection failure? > >Thank you. > >-----Original Message----- >7"<~HK: Vishal Salian <[EMAIL PROTECTED]> >JU<~HK: [EMAIL PROTECTED] <[EMAIL PROTECTED]> >HUFZ: 2000Dj5TB22HU 14:16 >VwLb: Re: Servlet with JDBC > > >>Try giving the Class.forName() in the init method of the servlet .This will >>create only one instance. >>Regards, >> >>Vishal >> >> >>>From: Xu Jianwu <[EMAIL PROTECTED]> >>>Reply-To: "A mailing list for discussion about Sun Microsystem's Java >>> Servlet API Technology." <[EMAIL PROTECTED]> >>>To: [EMAIL PROTECTED] >>>Subject: Servlet with JDBC >>>Date: Mon, 22 May 2000 13:23:34 +0800 >>> >>>I am developing servlets with JDBC API to access my database. In order to >>>ensure that the database connection is created only once for the threads >of >>>a servlet, where or when should I Class.forName() and >>>DriveManager.getConnection()? Should I override the construction method of >>>(e.g.) HttpServlet and do them there? >> >>________________________________________________________________________ >>Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com >> >>__________________________________________________________________________ _ >>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body >>of the message "signoff SERVLET-INTEREST". >> >>Archives: http://archives.java.sun.com/archives/servlet-interest.html >>Resources: http://java.sun.com/products/servlet/external-resources.html >>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html > >___________________________________________________________________________ >To unsubscribe, send email to [EMAIL PROTECTED] and include in the body >of the message "signoff SERVLET-INTEREST". > >Archives: http://archives.java.sun.com/archives/servlet-interest.html >Resources: http://java.sun.com/products/servlet/external-resources.html >LISTSERV Help: http://www.lsoft.com/manuals/user/user.html > Get your FREE Email at http://mailcity.lycos.com Get your PERSONALIZED START PAGE at http://my.lycos.com ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
Re: ;X84: Re: Servlet with JDBC
Venita, Rodrigues (CAP, Non GE, Wihpro) Thu, 25 May 2000 03:59:32 -0700
- Re: ;X84: Re: Servlet with JD... veena T
- Venita, Rodrigues (CAP, Non GE, Wihpro)
