helloDroid
helloDroid

Reputation: 654

exception in insert value in sqlite database android

i want to insert default value in database table

and i am using and put text string below:

INSERT INTO song_text VALUES(1,'Tell me girl, what's it gonna be I want you, baby do you want me You got me going insane, I'm losing my mind Is your love true, or am I wasting my time',1);

but it is giving exception:

12-02 14:11:37.860: ERROR/Database(568): Failure 1 (near "s": syntax error) on 0x247be8 when preparing 'INSERT INTO song_text VALUES(2,'Tell me girl, what's it gonna be

please give any solution.. thanks

Upvotes: 1

Views: 244

Answers (2)

Dimitris Makris
Dimitris Makris

Reputation: 5183

You should escape characters for your String, since for what's, it understands you have finished your String. Thus you should use: what\'s.

To be generic, you can use a method to replace all ' to \'. For example you may use:

private String convertString(String x) {
    return x = x.replace("'","\'");
}

Hope this helps!

Upvotes: 1

Caner
Caner

Reputation: 59168

You have to escape the apostrophes:

INSERT INTO song_text VALUES(1,'Tell me girl, what\'s it gonna be I want you, baby do you want me You got me going insane, I\'m losing my mind Is your love true, or am I wasting my time',1);

Upvotes: 3

Related Questions