Database problem

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Database problem

Postby Rashi » Thu Sep 10, 2009 12:02 pm

Hello,

I want to compare two strings in a query which i have written in SQLite database and has attaced to the application.
Problem is:
1.I am not able to compare them in the query.
2. I have tried making a new function to compare and call it but still it is not working and no rows are selected in cursor.

If you know any other way to connect a database and application please tell me or any other suggestion is welcome.

Thanks,
Rashi.
Rashi
Developer
Developer
 
Posts: 32
Joined: Thu Sep 10, 2009 11:28 am

Top

Postby nmc » Thu Sep 10, 2009 6:20 pm

I want to compare two strings in a query which i have written in SQLite database and has attaced to the application.
Problem is:
1.I am not able to compare them in the query.


Maybe you have to be more detailed, because comparing strings in sql is the same as in Basic/Pascal/Modula etc.:
select * from myTable where myTextField='hello'
(case sensitive in most sql dialects, maybe thats your problem?)
nmc
Senior Developer
Senior Developer
 
Posts: 154
Joined: Thu Nov 27, 2008 8:30 pm
Location: Germany

Postby Rashi » Fri Sep 11, 2009 2:38 pm

The problem is with the query which is:

Cursor mcursor=db.query(DATABASE_TABLE, new String[]{KEY_ID, KEY_Slang, KEY_Original, },KEY_Slang+"="+st,null,null, null,
null, null);

This the query which i am writing in adapter class, and the query description is as follows:
1. Key_Slang and Key_Original are my columns in the table.
2. st is the string i want to compare with Key_Slang, i have taken this string from the user, it is taken from editable text and converted to string, and want to compare it here to get the equivalent string from the database.

Here is the problem and the cursor returns nothing and the application closes by saying "Force Close".

Rashi.
Rashi
Developer
Developer
 
Posts: 32
Joined: Thu Sep 10, 2009 11:28 am

Postby nmc » Fri Sep 11, 2009 4:32 pm

KEY_Slang+"="+st

has to be KEY_Slang+"='"+st+"'";

In additon to that, the user could type a "'" into your editfield, then your code would crash again - so all "'" in st have to be quoted (or, use the selectionArgs parameter instead).

Personally, i prefer using rawQuery() rather than query()
nmc
Senior Developer
Senior Developer
 
Posts: 154
Joined: Thu Nov 27, 2008 8:30 pm
Location: Germany

Postby Rashi » Wed Sep 16, 2009 11:40 am

Thanks a lot. It really helped.
Rashi
Developer
Developer
 
Posts: 32
Joined: Thu Sep 10, 2009 11:28 am

Postby jss » Wed Sep 30, 2009 12:48 pm

Hi,
I am new to Android. I want to access a table in my android application. But the table is already created in SQLite through command prompt. Is it possible to do so?

The command that I used to create the database is C:\Android\android-sdk-windows-1.5_r2\tools>sqlite3.exe quizDB.db.

Please help me.


Thanks & Regards,
jss
jss
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Sep 29, 2009 8:25 am
Location: Mumbai

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 2 guests