Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8263955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:17:03+00:00 2026-06-08T04:17:03+00:00

So as I was learning Android, I got much advice on how to use

  • 0

So as I was learning Android, I got much advice on how to use ContentProvider and how to insert things correctly with that using SqliteDatabase. Now I have an error that makes no sense, at least with what everything everyone was telling me. The error is this:

android.database.sqlite.SQLiteException: near "s": syntax error:
while compiling: SELECT * FROM events WHERE time_stamp='07/21/2012 2:59:03 PM' AND
event='Test This's'

Everything works fine as long as ' doesn’t appear anywhere. I know why because it needs to be escaped. But this doesn’t make sense because everyone has been telling me to not use raw queries but rather use the provided bindings methods if that even made sense. Let me provide what my example is:

ContentValues newValues = new ContentValues();
newValues.put("event_id", eventId);
newValues.put("event_name", eventName);
newValues.put("start_date", startDate);
newValues.put("start_time", values.getAsString("start_time"));
newValues.put("end_date", endDate);
newValues.put("end_time", values.getAsString("end_time"));
newValues.put("location", values.getAsString("location"));
Long success = database.insert("events_info", null, newValues);

From what I have been able to understand, why should I need to escape this since its suppose to bind it!? Unless this only applies to the other methods like query() and update(). In either case I am hoping someone to shed some light on the proper practice in preparing Strings for SQLite insertion in Android. Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T04:17:07+00:00Added an answer on June 8, 2026 at 4:17 am

    SELECT * FROM events WHERE time_stamp=’07/21/2012 2:59:03 PM’ AND event=’Test This’s’

    As I think you know, the date string '07/21/2012 2:59:03 PM' is correctly delimited, and the event string 'Test This's' isn’t.

    The simple fix it change the string to 'Test This''s'

    The general problem, “how do you correct and validate input”, is actually a VERY big question – involving many more issues than just “quote” delimiters.

    Arguably your best line of defense is to use “query arguments”:

    EXAMPLE:
    p_query = "select * from mytable where name_field = ?";
    mDb.rawQuery(p_query, new String[] { uvalue });
    

    I had a surprisingly hard time finding a good tutorial on the topic – sorry. Here’s the best I could do:

    • http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/

    Here is a good article on a related topic, “SQL Injection”:

    • http://en.wikipedia.org/wiki/Sql_injection

    Finally, if you really want to “escape” your input string, you could do worse than use a simple Java String.replaceAll ():

    • http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been learning Android for about two weeks now (expert in as2/3). I have
I'm just learning Android. I have working piece of code that uses ContentValues: My
I am learning Android and have been working on an application that will need
I'm learning Android development. I have a basic app running on the Gingerbread emulator,
I have been working on learning the Android NDK the past few days, but
I am learning how to create an android app and webservice using: Eclipse IDE
I'm learning android development and I'm doing a minesweeper. So I use a tableLayout
I'm learning android now, and i write some simple codes according to the book.
Should I learn Java before learning Android or I can do both things in
When i started learning android i learned that R.java files goes to /gen folder

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.