public int getRecord(String tableName) throws SQLException{ 
      int c=0;
      try{
         rs=stmt.executeQuery("SELECT COUNT(Column1) as a from tableName");
         if(rs.next())
           c=rs.getInt("a");
         }
      catch(Exception e){      c=0;      }
       
      return c;
     }

解决方案 »

  1.   


       public int getColumnNumber(String tableName)
          throws SQLException
       {   int i=-1;
           try
           {
           if(rs!=null)
               rs.close();
           rs=stmt.executeQuery("SELECT COUNT(Column1) from tableName");
           i=rs.getInt(1);
          }
           catch(Exception e)
          {
             System.out.print("得到字段个数发生错误,Error " +e.toString());
          }
          return i;
       }
      

  2.   

    在zyhowe(冷月葬花魂)的代码基础上修改如下:public int getRecord(String tableName) throws SQLException{ 
          int c=0;
          try{
             rs=stmt.executeQuery("SELECT COUNT(Column1) as a from tableName");
             if(rs.next())
               c=rs.getInt("a");
             }
          catch(Exception e){
             System.out.println(e.getMessage());
             c=0;
          }
           
          return c;
         }