Hey!
I disagree with the way you are doing your DB connection,
but there are some very good servlet developers on this
list that disagree with me.
I don't put DB connections in the init(). Why you say.
Because I don't want any of my developers taking a long
term connection to my DB.
I put my connection code just before I need it and then let
it go as soon as I am done.
BTW, if you are truly doing the MVC you don't put the business
model in you controller code anyway. Try a different approach
like:
Creating a method() that is called inside of your doGet()/doPost().
Pass in your Driver, URL, props and query string and pass back
the result set. This is not perfect separation but it's a bit better.
A better way is to have a DB class that holds your business model.
Sans adieu,
Danny Rubis
Parvez Lanewala wrote:
> hi,
>
> i'm not getting why i'm getting this error.
> can someone help me.
>
> when i compile the following code :
>
> // this is in init() function
> .....
> .....
> Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
> Connection con=DriverManager.getConnection("jdbc:odbc:data1");
> Statement stmt=con.createStatement();
> ......
> ......
> protected void doPost(HttpServletRequest req,
> HttpServletResponse res)
> throws ServletException, IOException
> {
> ResultSet result;
> if(req.getParameter("action").equals("publisher"))
> {
> result=stmt.executeQuery("Select * from BookDetails");
> msg=result.getString(4);
> }
> ...
> ...
> ...
>
> This gives error as:
> ------------------------------------------------------------------
> data1.java:59: Undefined variable or class name: stmt
> result=stmt.executeQuery("Select * from BookDetails");
> ^
> ------------------------------------------------------------------
> Where do i define result ?
>
> Thanks.
> Parvez.
>
> ___________________________________________________________________________
> 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