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: http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=/com.ibm.db2.udb.admin.doc/doc/r0010873.htm https://www.ibm.com/support/knowledgecenter/en/SS6NHC/com.ibm.swg.im.dashdb.sql.ref.doc/doc/r0010873.html https://www.ibm.com/developerworks/community/blogs/SQLTips4DB2LUW/entry/merge?lang=en

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