Create SQLite database in android

Better example is here try { myDB = this.openOrCreateDatabase(“DatabaseName”, MODE_PRIVATE, null); /* Create a Table in the Database. */ myDB.execSQL(“CREATE TABLE IF NOT EXISTS ” + TableName + ” (Field1 VARCHAR, Field2 INT(3));”); /* Insert data to a Table*/ myDB.execSQL(“INSERT INTO ” + TableName + ” (Field1, Field2)” + ” VALUES (‘Saranga’, 22);”); /*retrieve data … Read more

Error Code: 1215. Cannot add foreign key constraint (foreign keys)

The most likely issue is this line: FOREIGN KEY (classLeader) REFERENCES student(studentID), The datatype of classLeader is VARCHAR(255). That has to match the datatype of the referenced column… student.studentID. And of course, the student table has to exist, and the studentID column has to exist, and the studentID column should be the PRIMARY KEY of … Read more

Does DB2 have an “insert or update” statement?

Yes, DB2 has the MERGE statement, which will do an UPSERT (update or insert). MERGE INTO target_table USING source_table ON match-condition {WHEN [NOT] MATCHED THEN [UPDATE SET …|DELETE|INSERT VALUES ….|SIGNAL …]} [ELSE IGNORE] See:

Spring data : CrudRepository’s save method and update

I wanted to know if the {save} method in CrudRepository do an update if it finds already the entry in the database The Spring documentation about it is not precise : Saves a given entity. Use the returned instance for further operations as the save operation might have changed the entity instance completely. But as … Read more

Entity Framework Code-first default data in database

You create custom initializer, which inherits from DropCreateDatabaseIfModelChanges or DropCreateDatabaseAlways interface. Like: public class EntitiesContextInitializer : DropCreateDatabaseIfModelChanges<-YourDbContext-> And then you overwrite Seed method like: protected override void Seed(YourDbContext context) Whole example might look like: public class EntitiesContextInitializer : DropCreateDatabaseIfModelChanges<EntitiesContext> { protected override void Seed(EntitiesContext context) { List<Role> roles = new List<Role> { new Role {Id=1, … Read more