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 ?
>
You went wrong in the init() method. In your case con and stmt are local
to the init() method. You should declare them as Fields of the class
(e.i. declare them right after you declare the class

public myclass{
  Connection con;
  Statement stmt;

  public void init(){
    con = ...;
    stmt = ...;
  }

}

This way it should work


--
-------------------------------------------------------------------------------------------
Sven E. van 't Veer                                                Afiliado
Universo Online
Gerente Desenvolvimento
Brasil Inform�tica e Telecomunica��es Ltda.
http://www.brvip.com.br
http://www.uol.com.br
-------------------------------------------------------------------------------------------

___________________________________________________________________________
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

Reply via email to