Traps that have been filled together in those years

Source: Internet
Author: User
Tags switch case


20140508

1. SQL statement, splicing query, adding single quotation marks for the string type, using =, and directly assigning values for the integer type

// Method 1

String SQL = "select ID, name from table_temp where name = 'host' Limit 30 offset 20 ";


DB. rawquery (SQL, null );

// Method 2 can I say it is not verified?

String SQL = "select ID, name from table_temp where name =? Limit? Offset? "


DB. rawquery (SQL, new string [] {name_value, limit_value, offset_value });

2. fuzzy query, using like, % placeholder

Three methods of fuzzy search


// Method 1


String SQL = "select ID, name from table_temp where name like '%" + keyValue + "' % ";

DB. rawquery (SQL, null );


// Method 2 not verified


String SQL = "select ID, name from table_temp where name like? ";


DB. rawquery (SQL, new string [] {keyValue });

3. Obtain the data in the returned value of cursor.

Problems encountered in the code today

Android. database. cursorindexoutofboundsexception: Index-1 requested, with a size of 1

I always thought it was a column query problem.

Google discovered that the subscript returned by cursor by default is-1. Before the value is set, move the subscript to a place with a return value.

After adding cursor. movetofirst (), there is no problem.

Explanation and stackoverflow description

4. I have to say that there is another more important thing today, and it is planted again under break.

In the switch case, the break is missing;

Traps that have been filled together in those years

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.