您的位置:首页 > 编程语言 > Java开发

Eclipse中main函数由控制台输入参数为空的处理

2013-06-06 16:46 302 查看
@简单的main函数:实现公司编码缺省时,这里将默认取所有公司编码
import java.sql.SQLException;
import com.evsoft.db.DataList;
import com.evsoft.db.Db;
public class teststr {
/**
* @param args
* @throws SQLException
*/
public static void main(String[] args) throws SQLException {
DataList gsbmList=null;
// TODO Auto-generated method stub
String sql=" select distinct col_1_1_1_3 as gsbm from 公司名称静态表 where 1=1 ";
if(args.length>0){
sql=sql+" and col_1_1_1_3 in("+args[0]+")";
}
gsbmList=Db.selectArrayList(sql);
while(gsbmList.next()){
gsbmList.getString("gsbm");
System.out.println(gsbmList.getString("gsbm"));
}
System.out.println(sql);
}
}

@注意:这里若用null来判断即 args[0]!=null,那么将报数组越界异常

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at com.evsoft.test.teststr.main(teststr.java:16)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: