为什么这么写会出现异常呢?
//上面代码省略
Connection connection = null;
try {
CallableStatement proc = null;
connection = getConnection(dataSource);
proc = connection.prepareCall(sql);//编译时候无错误,部署到tomcat中提示空指针异常
}
如果这样写就没有
Connection connection = null;
CallableStatement proc = null;
try {
connection = getConnection(dataSource);
proc = connection.prepareCall(sql);//无错误
}
[解决办法]
这个我这个问题,我之前已经遇到过,try..catch...finally,捕捉异常 CallableStatement proc = null;发现他为null,没有继续下去。所以CallableStatement proc = null必须写在外面