Obrigado a todos que ajudaram ..!!

----- Original Message -----
From: "Robson Luis Ferreira" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, October 18, 2002 3:05 PM
Subject: Re: [enterprise-list] NullPointerException


>    Darroio
>
>    Voc� n�o disse onde � que est� dando essa
> Exception, mas parece que � ao executar a query, por
> que voc� n�o instanciou seu objeto Statement (==
> null). Acrescente essa linha antes de executar o
> select.
>
>   statement = connection.createStatement();
>
>    Outro detalhe � que vc fecha o statement
> (statement.close()) antes de ler seu ResultSet, que
> acaba sendo fechado tamb�m.
>
>
>
>  --- [EMAIL PROTECTED] escreveu: > Bom dia !
> > Pessoal ! Segue abaixo o meu c�digo e estou com um
> > problema ( Null Pointer Exception )..
> > Se algu�m puder ajudar.. Grato !
> >
> >
> >
> >
> > import java.util.Date;
> > import java.io.*;
> > import java.util.*;
> > import java.sql.*;
> > import javax.servlet.*;
> > import javax.servlet.http.*;
> >
> >
> > public class ServiceServlet extends HttpServlet
> > {
> >     private String usuario;
> >     private String senha;
> >     private String query;
> >
> >     private static Connection connection = null;
> >     private static Statement statement = null;
> >     private static String url =
> > "jdbc:mysql://192.168.0.2/databov";
> >     private static String driver =
> > "org.gjt.mm.mysql.Driver";
> >
> >     // Initializes the servlet.
> >     public void init( ServletConfig config ) throws
> > ServletException
> >     {
> >         super.init( config );
> >
> >         try
> >         {
> >             Class.forName( driver );
> >             connection =
> >
> DriverManager.getConnection(url,"databov","cpbd1543k");
> >         }
> >         catch( Exception e )
> >         {
> >             e.printStackTrace();
> >             connection = null;
> >         }
> >     }
> >
> >
> >     public ResultSet executeQuery(String sql) throws
> > SQLException
> >     {
> >         return statement.executeQuery(sql);
> >     }
> >
> >
> >     public void service(HttpServletRequest request,
> > HttpServletResponse response)
> >                throws ServletException,
> > java.io.IOException
> >     {
> >
> >       response.setContentType("text/html");
> >         PrintWriter out = response.getWriter();
> >
> >        // Permite fazer a cria��o do cookie
> >         String cookieName = ( usuario );
> >         Date now = new Date();
> >         String timestamp = now.toString();
> >         Cookie cookie = new Cookie (cookieName,
> > timestamp);
> >         cookie.setDomain
> > ("localhost/databov/nocharpointer");
> >         cookie.setPath ("/nocharpointer");
> >         cookie.setMaxAge(7 * 24 * 60 * 60);
> >         cookie.setVersion ( 0 );
> >         cookie.setSecure(false);
> >         cookie.setComment("Cookie de usu�rio");
> >         response.addCookie (cookie);
> >
> >         usuario = request.getParameter("user");
> >         senha = request.getParameter("pass");
> >
> >         //Fazendo a valida��o
> >         if( usuario.equals( "" ) || senha.equals( ""
> > ) )
> >         {
> >             out.println( "<H3> Por favor preencha
> > corretamente o login e senha</h3>" );
> >             response.sendRedirect("/erro.jsp");
> >         }
> >
> >         try
> >         {
> >
> >             query = "SELECT * from cadastro where
> > username = " + usuario + " and senha = " + senha + "
> > ";
> >             ResultSet results =
> > statement.executeQuery( query );
> >             statement.close();
> >
> >             if( results.first() )
> >             {
> >
> > response.sendRedirect("/logado.jsp");
> >
> >             }
> >             else
> >             {
> >                 response.encodeURL("/erro.jsp");
> >
> >             }
> >
> >         }
> >         catch( Exception e )
> >         {
> >             System.err.println("Error: Problema ao
> > fechar o banco de dados ");
> >             e.printStackTrace();
> >
> >
> >         }
> >
> >     }
> >
> >     // Destroys the servlet
> >     public void destroy()
> >     {
> >         try
> >         {
> >            connection.close();
> >         }
> >         catch( Exception e )
> >         {
> >             System.err.println("Erro n�o foi
> > poss�vel fechar o bando");
> >         }
> >
> >     }
> > }
>
> =====
> Robson Luis Ferreira
> [EMAIL PROTECTED]
> Tel: (11) 9827-6406
>
> _______________________________________________________________________
> Yahoo! GeoCities
> Tudo para criar o seu site: ferramentas f�ceis de usar, espa�o de sobra e
acess�rios.
> http://br.geocities.yahoo.com/
>
> ---------------------------------------------------------------------
> Para cancelar a subscri��o, envie mensagem para:
[EMAIL PROTECTED]
> Para comandos adicionais, envie mensagem para:
[EMAIL PROTECTED]
>

---------------------------------------------------------------------
Para cancelar a subscri��o, envie mensagem para: 
[EMAIL PROTECTED]
Para comandos adicionais, envie mensagem para: [EMAIL PROTECTED]

Responder a