Android query SQLIte syntax error

I receive data from an Activity in which I create a SQL query, but I'm getting syntax error in string. Thanks for help

String sql = "SELECT _Id,Date,cas,N,E,Altro FROM Ge WHERE Ea>0 AND cas LIKE "+c_ricevuta+" AND date LIKE '"+anno_ricevuto+"-%' ORDER BY data DESC";

here syntax error: cas LIKE "+c_ricevuta+"

Answers


c_ricevuta should likely be in single quotes '':

String sql = "SELECT _Id,Date,cas,N,E,Altro FROM Ge WHERE Ea>0 AND cas LIKE '"+c_ricevuta+"' AND date LIKE '"+anno_ricevuto+"-%' ORDER BY data DESC";

Note that using string params in your query like this is prone to both syntax errors and SQL injection. Have a look at ? literal placeholders instead, e.g. the selectionArgs in query functions.


just in case, I'd place spaces between the word and the "+". Plus, you're not using quotes to surround c_ricevuta


Need Your Help

Multi-column Floated Divs Row Issue

jquery css

I need a primarily css or js way to have div floats on a different row drop into the excess height, bad description, I know. Here is a example: http://jsfiddle.net/aPwtR/1/

Activity struck while pressing back key

android android-activity listactivity

There is no action performed on the activity when i press back key till some time. No code return to handle back key in my activity. I am starting a activity when user clicks on list item. Like

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.