int MaxLength = -1;
         try
         {
          if(rs.getInt(3) != -1)
          {
                 MaxLength = rs.getInt(3);//可用词中最大词长 可能抛出异常
          }
         }
         catch(Exception e)
         {    
          System.out.println("ERROR!");
             return MaxLength;
         }
怎么老是出错啊?
总是出错,而执行catch中的内容?

解决方案 »

  1.   

    在catch里面直接输出异常,不要就打印一个error,这样你又不知道异常是什么
      

  2.   

    应该这样写:
    int MaxLength = -1; 
             try 
             { 
                int temp = rs.getInt(3);
              if(temp != -1) 
              { 
                     MaxLength = temp; 
              } 
             } 
             catch(Exception e) 
             {     
              System.out.println("ERROR!"); 
                 return MaxLength; 
             } 
    你对同一列做两次getInt(3)会有问题的
      

  3.   

    不行还是出错啊?
       int MaxLength = -1;
             try  
             {  
                int temp = rs.getInt(3); 
              if(temp != -1)  
              {  
                     MaxLength = temp;  
              }  
             }  
             catch(Exception e)  
             {      
              System.out.println(e.getMessage());
                 return MaxLength;  
             }  
    出错输出是:Before start of result set
      

  4.   

    while (rs.next()) {
     你的代码
    }
      

  5.   

    lz可以这样实现:
    int MaxLength = -1; 
             try 
             { 
              if(rs.next()&&rs.getInt(3) != -1) 
              { 
                     MaxLength = rs.getInt(3);//可用词中最大词长 可能抛出异常 
              } 
             } 
             catch(Exception e) 
             {     
              System.out.println("ERROR!"); 
                 return MaxLength; 
             } 
      

  6.   

    如 7楼所说 需要先用 rs.next() 才能进行判断和get值 
      

  7.   


    catch(Exception e){
       e.printStackTrace();//看看你的出错信息是什么!按你那样异常信息都丢了!SQLException出这个异常了,怀疑你的columnIndex有问题!
    }
      

  8.   

    anqini说的有道理,我也觉得他的列有错。