Android
[안드로이드] SQL Like 검색
누르님
2017. 4. 25. 00:08
안드로이드에서 SQLite like 검색 방법입니다.
SQL Like 검색시 사용 방법
protected Cursor select(String tableName, String col1, String Like) throws SQLiteException{ return getReadableDatabase().query(tableName, null, col1+ " LIKE ?", new String[] {"%"+ Like+ "%" }, null, null, null, null); }
SQL Like 검색시 (OR, AND) 사용 방법 (두개 이상의 컬럼시)
- 당연한 얘기이겠지만, 이렇게 사용하면 성능이 현저히 떨어지기 때문에 권장하지 않습니다.
protected Cursor select(String tableName, String col1, String col2, String Like) throws SQLiteException{ return getReadableDatabase().query(true, tableName, null, col1+" LIKE '%"+Like+"%' or "+col2+" LIKE '%"+Like+"%'", null, null, null, null, null); }