2011-06-18 2 views

Répondre

1

Count fait (0) faire aussi un tour, et pour obtenir un résultat, il est la première et la seule ligne de curseur, premier champ, type int:

public static int selectRecordsCount(String dbUrl, String tableName) 
      throws DatabaseException, DataTypeException, 
      IllegalArgumentException, MalformedURIException { 
     int result = -1; 
     URI myURI = URI.create(dbUrl); 
     Database d = DatabaseFactory.open(myURI); 
     Statement st = d.createStatement("SELECT COUNT(0) FROM " 
       + String.valueOf(tableName)); 
     st.prepare(); 
     Cursor c = st.getCursor(); 
     c.next(); 
     result = c.getRow().getInteger(0); 
     st.close(); 
     d.close(); 
     return result; 
    } 
Questions connexes