I pretty recommend to you use API method of SQLiteDatabase db.insert() that is directly designated for inserting new rows to table. This solution is cleaner.
public void insertIntoDatabase(String field_one, String field_two){
ContentValues data = new ContentValues();
data.put("COL_USERNAME", field_one);
data.put("COL_PASSWORD", field_two);
if (db == null) {
// make sure that your db is properly initialised
}
db.insert("tablename", "nullColumnHack", data);
}
Explanation of nullColumnHack:
If your provided values is empty, no column names are known and an
empty row can't be inserted. If not set to null, the nullColumnHack
parameter provides the name of nullable column name to explicitly
insert a NULL into in the case where your values is empty.
It means that in Android SQLite you have to specify one column that will be assign NULL to in the case if you pass empty ContentValues.
If you want to use your approach i recommend to you an usage of placeholders.
String sql = "INSERT INTO UserTable.NAME (COL_USERNAME, COL_PASSWORD) " +
"VALUES (?, ?)";
db.execSQL(sql, new String[] {field_one, field_two});
Note: Probably it didn't work because you didn't use single quotes.
VALUES ("' + field_one + '", "' + field_two + '")"
And also make sure that given tablename is correct. I recommend to create static variables which will hold tablename and column names.
public static final String TABLE_NAME = "Table";
String query = "insert into " + ClassName.TABLE_NAME + " values(?, ?)"