0

Does anyone know why I am getting a null pointer error when I call the getResultSet() method from MyServ2 class

here is my DBClass (imports etc omitted)

public DBClass(){

    }

public Connection dbConnect(String db_connect_string,
        String db_userid, String db_password)
{

        try
        {
        DriverManager.registerDriver(new oracle.jdbc.OracleDriver());

        conn = DriverManager.getConnection(
        db_connect_string, db_userid, db_password);

        return conn;

        }
        catch (Exception e)
            {
                e.printStackTrace();

                return null;
            }
}



public ResultSet getResultSet(String query){

    try{
    stmt = conn.createStatement();
    result = stmt.executeQuery(query);  

    } catch(Exception e){
        e.printStackTrace();
        return null;
    }
    return result;

}



} 

and this is my MyServ2 class

public class MyServ2 extends HttpServlet {
    private static final long serialVersionUID = 1L;
       private DBClass db;

    public MyServ2() {
        super();
        db = new DBClass();

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        ResultSet rs = db.getResultSet("Select * from ....ect");
        try {
            while(rs.next()){
                System.out.println(rs.getString(1).toString());
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

}
1
  • 2
    You are not calling dbConnect method i think. therefore you are not connected to db and your query returns null. Commented Nov 26, 2010 at 12:24

1 Answer 1

6

You're not calling db.dbConnect(), so db.conn will be null.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.