Skip to content Skip to sidebar Skip to footer

Dynamic Table Creation On Button Click In SQLite

I am creating a login application and I wanted to create a table for each user when they click the register button. The problem is, I am using their unique email id as table name.

Solution 1:

In SQL, identifiers can be quoted with double quotes. Any double quotes inside the identifier must be doubled to escape them; and in Java strings, double quotes must be escaped with a backslash:

String sqlTableName = "\"" + email.replace("\"", "\"\"") + "\"";
db.execSql("CREATE TABLE " + sqlTableName + "...");

However, putting data into the table name is a bad idea, because it cannot be queried and modified like all your other data.

Better use a single table, and put that information into another column:

CREATE TABLE Users(EMail TEXT, Choice TEXT, Q...);

Post a Comment for "Dynamic Table Creation On Button Click In SQLite"