简体   繁体   English

NullPointerException - 使用Java执行SQL

[英]NullPointerException - Using Java to Execute SQL

I have the following Code that throws a null pointer exeption 我有以下代码抛出空指针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? 您是否检查过以确保stmt不为空? 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. 编写函数的方式,它必须是一个字段,并且必须确保它在checkAcc()之前已经初始化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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