首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

为什么这么写会出现错误呢

2013-08-09 
为什么这么写会出现异常呢?//上面代码省略Connection connection nulltry {CallableStatement proc n

为什么这么写会出现异常呢?
//上面代码省略


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必须写在外面

热点排行