1.if ((request.getParameter("code_t")!=null) 2. if (s_code_t.equals(""))//
if (s_code_t!=null) ~~~~~~~~~~ { rs=conn.executeQuery("select * from complex where code_s='"+s_code_s+"'"); ~~~~~~~~~ }你一个变量写成s_code_t,一个变量写成s_code_s,当然报错
1.if ((request.getParameter("code_t")!=null) 2. if (s_code_t.equals(""))//
///////////////没有catch exception if (s_code_t!=null) { try{ rs=conn.executeQuery("select * from complex where code_s='"+s_code_s+"'"); }catch(SQLException){ } } while (rs.next()) { }
2.
if (s_code_t.equals(""))//
~~~~~~~~~~
{
rs=conn.executeQuery("select * from complex where
code_s='"+s_code_s+"'");
~~~~~~~~~
}你一个变量写成s_code_t,一个变量写成s_code_s,当然报错
while{
}....
放到判断条件里面就行了!ResultSet rs;改成ResultSet rs=null;也可以通过编译,但如果运行时code_t参数为null的话就要抛出NullPointerException了.
2.
if (s_code_t.equals(""))//
if (s_code_t!=null)
{
try{
rs=conn.executeQuery("select * from complex where code_s='"+s_code_s+"'");
}catch(SQLException){
}
}
while (rs.next())
{
}
(1)变量rs没有初始化!
(2)s_code_t按上下文可知是个字符串对象,经行“String s_code_t=request.getParameter("code_t");”的作用,有可能得到的是null对象或者值为空字符串""的对象,所以,判断s_code_t不为空的情形宜用(s_code_t!=null && !s_code_t.equals("")),当然你的判断语句“s_code_t!=null”写法没错,但是逻辑不严密!
(3)s_code_s是否之前有定义?还是你把s_code_t错写成s_code_s???!!!
(4)逻辑不对,while语言应该放在if语句内部!
这样的写法就不好。看看 迈克尔·老鬼 的写法。
用if(true) return;分别在if前和if后测试一下
测试一下如果是你试试将s_code_t单独声明一下
String s_code_t = new String();
String s_code_t=request.getParameter("code_t");
改为:
String s_code_t=request.getParameter("code_t")==null?null:request.getParameter("code_t").toString();
即可
:p
这位大哥说得对.应该将while放在判断句里面去.
多谢各位宝贵意见.
好好看看Eraserpro(穷...哪位好人拿钱砸我吧!!!) ( )