tags:

views:

107

answers:

3

i want to write this line in an sqlight db b:

CREATE TABLE "android_metadata" ("locale" TEXT DEFAULT 'en_US')

therefore in my java file who generate this data base i am doing :

stat.executeUpdate("create table "+"android_metadata"+"("+"locale"+ " TEXT DEAFULT"+");");
    PreparedStatement prep1 = conn.prepareStatement(
              "insert into "+"android_metadata"+" values (?);");
    prep1.setString(1, "en_US") ;

but the output is not similer how do i make the sqlight locale be "locale" with "" in the declaration and the field locale would be just TEXT

as similer to this blog start : http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/

thanX

+3  A: 

You need to escape the quote symbol (and fix a typo - DEAFULT)

stat.executeUpdate("create table \"android_metadata\" (\"locale\" TEXT DEFAULT 'en-US');");
Blorgbeard
thanx men to b honest i was trying to back slash it but with / rather then using \ the bugs who eats your life ...thank u :)
yoav.str
+6  A: 

To escape the double quotes use a backslash:

stat.executeUpdate("create table \"android_metadata\" (\"locale\" TEXT DEFAULT 'en_US');");

Also I think you don't need double quotes round android_metadata as it is not an SQL keyword.

Mark Byers
+2  A: 

The java String equivalents are:

// CREATE TABLE "android_metadata" ("locale" TEXT DEFAULT 'en_US')
final static private String create = "CREATE TABLE \"android_metadata\" (\"locale\" TEXT DEFAULT 'en_US')";

// INSERT INTO "android_metadata" VALUES ('en_US')
final static private String insert = "INSERT INTO \"android_metadata\" VALUES ('en_US')";

EDIT upgraded the code according to duffymos comment :)

Andreas_D
Both these Strings should be static and final.
duffymo
@duffymo, this is just a java-like example how the String should look like. Not even a snippet.
Andreas_D
You and I know that, but the OP doesn't. S/he had them embedded in the execute method. I thought it'd be worth pointing out.
duffymo