Variavel de Sessao - NULL

1 resposta
E

Bom Dia!!!

Não sei por qual razão mas minhas variaveis de sessao esta retornando nulo…

Fiz da seguinte forma:

EM MINHA SERVLET

VariaveisSessao var = new VariaveisSessao();
String sessao = var.Insert(request, response);

EM MINHA CLASSE

package model;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class VariaveisSessao {
	private ConexaoMysql conexaoMysql;
	
	public VariaveisSessao() {   
        //ConexaoMysql conexaoMysql;   
    } 

    public String Insert(HttpServletRequest request, HttpServletResponse response) {   
        HttpSession session = request.getSession(); 
    	String matricula = (String)session.getAttribute("login"); 
    	
        conexaoMysql = new ConexaoMysql(); 
        Statement state = null;   
        ResultSet rs = null;   

        try {  
         	state = conexaoMysql.getConnection().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);   
            rs = state.executeQuery("Select perfil, nome from users where matricula = '" + matricula + "'");

            String nome = rs.getString("nome");
            String perfil = rs.getString("perfil");
            
            session.setAttribute("nome", nome);
            session.setAttribute("perfil", perfil);
            
        } catch(Exception erro) {   
            System.out.println("Erro ocorrido na classe VariaveisSessao: n" + erro);   
        } finally {   
        	if(state != null){   //fechar os statments
				try {
					state.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}  
        	}   
        	if(rs != null){   
				try {
					rs.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}   
        	conexaoMysql.closeConnection();   
        }
		return matricula;  
    }
}

E quando peço para exibir em meu jsp as variaveis estao nulas.

??

1 Resposta

E

RESOLVIDO!!!

Tive que fazer o rs.next();

Criado 25 de junho de 2009
Ultima resposta 25 de jun. de 2009
Respostas 1
Participantes 1