简单 数据库 查询

1. 得到目标数据库的Cursor 如:联系人

Cursor c = getContentResolver().query(People.CONTENT_URI, 
                null, null, null, null);

2. 查询该数据库中 指定id 指定列 的数据

public String getValueByColumnId(Cursor c, String columnName, int id){
    	if(id >= c.getCount()){
    		//id越界
    		return "";
    	}
    	else {
    			c.moveToPosition(id);
    	    	
    	    	int columnIndex = c.getColumnIndex(columnName);
    	    	return c.getString(columnIndex);
    	}
    	
    	
    }

3. 使用: 如 查询联系人中 第2记录 且 列名People.NAME 的记录

String s2 = getValueByColumnId(c,People.NAME,2);

结束之!!!