站内搜索: 请输入搜索关键词

当前页面: 开发资料首页J2EE 专题高手进来看看~

高手进来看看~

摘要: 高手进来看看~


try {
a = Integer.parseInt(kob.getArea());
System.out.print(a);
} catch (NumberFormatException ex1) {
System.out.print(ex1);
if (ex1.equals("") || ex1 == null) {
String tsql = "select * from crm_areathree where id =" + a;
rs = stmt.executeQuery(tsql);
}
您看这样的话 如果 取出来的是 INT那就已经赋值给a了 我要是做数据库操作的话 只能查id=a的 那他的作用域不够啊~






晕...
你定义的a在try外面
int a = 0
try{
a = ??;
}
catch(){

}
a的作用域在整个方法都适用


int a = 0;

try {
a = Integer.parseInt(kob.getArea());
System.out.print(a);
} catch (NumberFormatException ex1) {
System.out.print(ex1);
if (ex1.equals("") || ex1 == null) {
String tsql = "select * from crm_areathree where id =" + a;
rs = stmt.executeQuery(tsql);
}



try {
a = Integer.parseInt(kob.getArea());
System.out.print(a);
if (ex1.equals("") || ex1 == null) {
String tsql = "select * from crm_areathree where id =" + a;
rs = stmt.executeQuery(tsql);

} catch (NumberFormatException ex1) {
System.out.print(ex1);
}
最好改成这样



catch里面写这些,少见。。。这样不会提高代码效率


try {
a = Integer.parseInt(kob.getArea());
System.out.print(a);
} catch (NumberFormatException ex1) {
System.out.print(ex1);
if (ex1.equals("") || ex1 == null) {
String tsql = "select * from crm_areathree where id =" + a;
rs = stmt.executeQuery(tsql);
}
======================================
这什么乱七八糟的,有这么用的么?

==>

try {
int a = Integer.parseInt(kob.getArea());
//System.out.println(a);
String tsql = "select * from crm_areathree where id =" + a;
rs = stmt.executeQuery(tsql);
} catch (NumberFormatException ex1) {
ex1.printStackTrace();
}



这个是为了补获异常操作 因为在数据库读取出来的时候无法判断是不是数字还是字符串所以利用异常来进行控制~见笑了各位 问题解决了~~


up


建议 if (ex1.equals("") || ex1 == null) {
改为 if (ex1 == null||ex1.equals("")) {
否则出错


ex1怎么可能equals("")?
牛头不对马嘴啊


↑返回目录
前一篇: 关于文件上传的苦恼!!!!(三天没解决的问题,救急)
后一篇: 在JAVA中通过代理访问网络有那些方法?