简体   繁体   中英

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);
    }
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM