Your 'result' definition is not the problem.
stmt is defined in init() which makes it local to that method, but you are
trying to use it in doPost(). You need to define "Statement stmt" outside
the methods which will allow both init() and doPost() to to execute methods
for that class -

public CLASS xxx extends HttpServlet
{
  Statement stmt;

  public void init(ServletConfig cfg) throws ServletException
  {
    stmt = con.createStatement();
    ...
  }

  ... doPost(..)
  {
     // Same commands as you have below...
  }

}


John.

-----Original Message-----
From: Parvez Lanewala [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 27, 2000 7:59 PM
To: [EMAIL PROTECTED]
Subject: new to JDBC !!!


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

Reply via email to