android


how to write a where clause in sqlite query to gain the exact value?


hi i have a poem database and i want to search in the poems this is what my code look like now
public ArrayList searchthequeryforme(String inputText) {
// TODO Auto-generated method stub
String[] columns = new String[] { KEY_ROWID, KEY_TEXT, KEY_TITLE };
Cursor c = mydatabase.query(true,TABLE_POEM, columns, KEY_TEXT+" like '%"+inputText+"%'", null, null,
null, null, null);
ArrayList<poem> myarray = new ArrayList<poem>();
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
poem = new poem(c.getInt(0), c.getString(1), c.getString(2));
myarray.add(poem);
}
return myarray;
}
but in this case if i search for "poem" for example it retrieves the records in which i have "poet" and it comes with a text that actually doesnt have "poem" i want to get the exact records what should my query look like?
That's what the LIKE operator does. To get an exact match, change
KEY_TEXT+" like '%"+inputText+"%'"
to
KEY_TEXT+"='"+inputText+"'";
If you are interested in using framework instead of coding the database access code, then, please look at Active Android (http://www.activeandroid.com/). It has some very nice query access API as you can from examples here: https://github.com/pardom/ActiveAndroid/wiki/Querying-the-database

Related Links

android programming : I want to have a specific folder like whatsapp have to store its app file?
Firebase Android Load image to ImageView from storage
How to optimize(reduce) the size of my android app
Responsive Angular 2 web-app to mobile app
Change listview text Android
Why brcm_wlan_init in Cyanogenmod is not working?
Create Non Readable Directory in Android
Android: Changing the default acitivity removes access to application
Toolbar menu item text gets chopped off
Related to toolbar,multiple screens layout etc
Reduce game size in Cocos Creator cocos2d-x
Cast String data type to double in Firebase
Error:Failed to resolve: com.twitter.sdk.android:twitter:2.3.0 - Android Studio
Android hamburger icon on navigation drawer does not respond after clicking
Periodic processing with Timeline and lambda expression does not work with Javafx8 for android (gluon)
Firebase Orderby Query not working

Categories

HOME
google-app-engine
xml
numbers
devise
pclxl
spring-data-mongodb
pyqt4
tvos
spring-session
frontend
jsonpath
pybossa
fileserver
googlebot
imagemap
roslyn
interbase
bringtofront
cppreference
gp
livelink
postback
mockjax
left-join
cart
git-squash
twos-complement
carriage-return
sql-delete
browser-extension
magento-1.9.2.4
alphabetical
health-monitoring
opensmpp
odoo-website
wmp
subclipse
glm-math
photos
puredata
jboss-4.2.x
magento-2.0.7
reportservice2010
azure-cli
arules
cup
chromium-os
mapxtreme
flex-monkey
lrs
watch-os-2
mta
jclouds
cda
uiactionsheet
pushbots
grass
crouton-os
linklabel
dock
pax-exam
avahi
user-permissions
cross-join
boost-program-options
easyrtc
teaspoon
universal-image-loader
encryption-asymmetric
ora-00904
alternate
sbcl
nevron
merb
time.h
chart-director
redis-py
subproject
usertype
hibernateexception
gobject-introspection
android-holo-everywhere
interprocess
openfaces
tabpanel
google-wave
todos
java1.4

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App