Olly Stredwick
Olly Stredwick

Reputation: 71

NullPointerException - Using Java to Execute SQL

I have the following Code that throws a null pointer exeption

public void checkAcc(String sql)
{
    System.out.print(sql);   // the statement executed is "SELECT AccountID FROM BankAccount"    
    try {
        stmt.executeQuery(sql);

    } catch (Exception e) {
        System.err.println("Nope that is broken - " + e);
    }
}

Upvotes: 0

Views: 93

Answers (1)

Jim Kiley
Jim Kiley

Reputation: 3652

Have you checked to ensure that stmt isn't null? The way that function is written, it must be a field, and you have to make certain that it has been initialized before checkAcc() is called.

Upvotes: 2

Related Questions