Mysql数据库,查询结果为空值,如何处理?

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/choath/article/details/80686475

当sql查出空值的时候,如果想要获取,其中的值可能会出错!

a=res.getString("字段")   如果该字段的值是null,就会报错!

所以需要在取字段值的时候做try{}catch{}处理!

try{

a=res.getString("字段");

}catch{

a="";

如果try出错,赋值一个默认值为,空字符串!

猜你喜欢

转载自blog.csdn.net/choath/article/details/80686475
今日推荐