public User[] getAllUser() { Vector<User> v = new Vector<User>(); Cursor cursor = null; try { cursor = db.find("select * from " + TABLENAME, null); while (cursor.moveToNext()) { User temp = new User(); temp.setId_DB(cursor.getInt(cursor.getColumnIndex("id_DB"))); temp.setAddress(cursor.getString(cursor.getColumnIndex(User.ADDRESS))); temp.setQq(cursor.getString(cursor.getColumnIndex(User.QQ))); temp.setDanwei(cursor.getString(cursor.getColumnIndex(User.DANWEI))); temp.setName(cursor.getString(cursor.getColumnIndex(User.NAME))); temp.setMobile(cursor.getString(cursor.getColumnIndex(User.MOBILE))); v.add(temp); } } catch (Exception e) { e.printStackTrace(); } finally { if (cursor != null) cursor.close(); db.closeConnection(); } if (v.size() > 0) { return v.toArray(new User[] {}); } else { User[] users = new User[1]; User user = new User(); user.setName("无结果111"); users[0] = user; return users; } }
public User getUserByID(int id) { Cursor cursor = null; try { cursor = db.find("select * from " + TABLENAME + " where id_DB=?", new String[] {id + ""}); User temp = new User(); cursor.moveToNext(); temp.setId_DB(cursor.getInt(cursor.getColumnIndex("id_DB"))); temp.setAddress(cursor.getString(cursor.getColumnIndex(User.ADDRESS))); temp.setQq(cursor.getString(cursor.getColumnIndex(User.QQ))); temp.setDanwei(cursor.getString(cursor.getColumnIndex(User.DANWEI))); temp.setMobile(cursor.getString(cursor.getColumnIndex(User.MOBILE))); temp.setName(cursor.getString(cursor.getColumnIndex(User.NAME))); return temp; } catch (Exception e) { e.printStackTrace(); } finally { if (cursor != null) { cursor.close(); } db.closeConnection(); } return null; }