Dbhelper Class In Java
124 /** LR classes supported at present */ 125 public static final String DOCUMENT_CLASS = 'gate.corpora.DatabaseDocumentImpl'; 126 /** LR classes supported at present */ 127 public static final String CORPUS_CLASS = 'gate.corpora.DatabaseCorpusImpl'; 128 129 /** key in T_PARAMETER that defines a unique id for the data store */. A guest Apr 28th, 2016 52 Never Not a member of Pastebin yet? Sign Up, it unlocks many cool features! Raw download clone embed report print Java 3.98 KB public class DbHelper extends SQLiteOpenHelper { public static final String DB_NAME = 'articoli.db'; public. Inserting and Deleting values in with my DBhelper class. Here is my compelete dbhelper object. Public class DatabaseHelper extends SQLiteOpenHelper { // The. Since the contructor is private the only way to get an instance of that class is calling static method getInstance of class A, so now whenever you call A.getInstance() it will return either a new object or an object that already been instantiated. Package name and Class name matching the fully-qualified Class name entered in RSA. Extension of the 'ActionInstance' Class Database queries (using the dbHelper object created by the 'ActionInstance' superclass). Class DBHelper java.lang.Object gate.persist.DBHelper. Public class DBHelper extends Object. Field Summary: static int: BINARY_CONTENT binary content (may make difference for the database) static int: CHARACTER_CONTENT character content (may make difference for the database).
PermalinkJoin GitHub today
Scanner Class In Java
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upDbhelper Class In Java 10
packagecom.moczul.notepad; |
/** |
* @author MichaĆ Moczulski |
* twitter_url: http://twitter.com/#!/moczul |
*/ |
importjava.util.Date; |
importandroid.content.ContentValues; |
importandroid.content.Context; |
importandroid.database.Cursor; |
importandroid.database.sqlite.SQLiteDatabase; |
importandroid.database.sqlite.SQLiteOpenHelper; |
publicclassDBHelperextendsSQLiteOpenHelper { |
privateContext ctx; |
//version of database |
privatestaticfinalint version =1; |
//database name |
privatestaticfinalStringDB_NAME='notesDB'; |
//name of table |
privatestaticfinalStringTABLE_NAME='notes'; |
//column names |
privatestaticfinalStringKEY_ID='id'; |
privatestaticfinalStringKEY_TITLE='noteTitle'; |
privatestaticfinalStringKEY_CONTENT='noteContent'; |
privatestaticfinalStringKEY_DATE='date'; |
//sql query to creating table in database |
privatestaticfinalStringCREATE_TABLE='CREATE TABLE '+TABLE_NAME+' (id INTEGER PRIMARY KEY AUTOINCREMENT, '+KEY_TITLE+' TEXT NOT NULL, '+KEY_CONTENT+' TEXT NOT NULL, '+KEY_DATE+' TEXT);'; |
//contructor of DBHelper |
publicDBHelper(Contextcontext) { |
super(context, DB_NAME, null, version); |
this.ctx = context; |
} |
//creating the table in database |
@Override |
publicvoidonCreate(SQLiteDatabasedb) { |
db.execSQL(CREATE_TABLE); |
} |
//in case of upgrade we're dropping the old table, and create the new one |
@Override |
publicvoidonUpgrade(SQLiteDatabasedb, intarg1, intarg2) { |
db.execSQL('DROP TABLE IF EXIST '+TABLE_NAME); |
onCreate(db); |
} |
//function for adding the note to database |
publicvoidaddNote(Stringtitle, Stringcontent) { |
SQLiteDatabase db =this.getWritableDatabase(); |
//creating the contentValues object |
//read more here -> http://developer.android.com/reference/android/content/ContentValues.html |
ContentValues cv =newContentValues(); |
cv.put('noteTitle', title); |
cv.put('noteContent', content); |
cv.put('date', newDate().toString()); |
//inserting the note to database |
db.insert(TABLE_NAME, null, cv); |
//closing the database connection |
db.close(); |
//see that all database connection stuff is inside this method |
//so we don't need to open and close db connection outside this class |
} |
//getting all notes |
publicCursorgetNotes(SQLiteDatabasedb) { |
//db.query is like normal sql query |
//cursor contains all notes |
Cursor c = db.query(TABLE_NAME, newString[] {KEY_TITLE, KEY_CONTENT}, null, null, null, null, 'id DESC'); |
//moving to the first note |
c.moveToFirst(); |
//and returning Cursor object |
return c; |
} |
publicCursorgetNotes2(SQLiteDatabasedb) { |
//db.query is like normal sql query |
//cursor contains all notes |
Cursor c = db.query(TABLE_NAME, newString[] {KEY_ID, KEY_TITLE}, null, null, null, null, 'id DESC'); |
//moving to the first note |
c.moveToFirst(); |
//and returning Cursor object |
return c; |
} |
publicCursorgetNote(SQLiteDatabasedb, intid) { |
Cursor c = db.query(TABLE_NAME, newString[] {KEY_TITLE, KEY_CONTENT, KEY_DATE}, KEY_ID+' = ?', newString[] { String.valueOf(id) }, null, null, null); |
c.moveToFirst(); |
return c; |
} |
publicvoidremoveNote(intid) { |
SQLiteDatabase db = getWritableDatabase(); |
db.delete(TABLE_NAME, KEY_ID+' = ?', newString[] { String.valueOf(id) }); |
db.close(); |
} |
publicvoidupdateNote(Stringtitle, Stringcontent, StringeditTitle) { |
SQLiteDatabase db =this.getWritableDatabase(); |
ContentValues cv =newContentValues(); |
cv.put('noteTitle', title); |
cv.put('noteContent', content); |
cv.put('date', newDate().toString()); |
db.update(TABLE_NAME, cv, KEY_TITLE+' LIKE ''+ editTitle +''', null); |
db.close(); |
} |
} |
Dbhelper Class In Java C
Copy lines Copy permalink