Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development

Application Development Dev Lounge for the Coder Folks



Reply
 
LinkBack Thread Tools
Old February 2nd, 2012, 02:46 AM   #1 (permalink)
New Member
 
Join Date: Feb 2012
Location: Indore
Posts: 7
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default open,close database,insert values,fetch values, update and delete values in database

//--------open database -----------------

public SQLiteDatabase openDataBase() throws SQLException {
// Open the database
String myPath = DB_PATH + DB_NAME;
return myDB = SQLiteDatabase.openDatabase(myPath, null,
SQLiteDatabase.OPEN_READWRITE);
}

//-------close database------------

@Override
public synchronized void close() {
if (myDB != null)
myDB.close();
super.close();
}

//---------insert query to insert entry in database---------

public long insertUser(String uname,String upass) {
try{
myDB = this.getWritableDatabase();
String insertUser = "insert into user (username,password) values (?,?)";
this.insertStmt = myDB.compileStatement(insertUser);
this.insertStmt.bindString(1, uname);
this.insertStmt.bindString(2, upass);
}catch(Exception er){
er.printStackTrace();
}
return this.insertStmt.executeInsert();
}

//--------select query to fetch data from database-------------

public ArrayList<String> selectloginpass() {
// boolean success = false;
openDataBase();
ArrayList<String> user_id_pass = new ArrayList<String>();
try{

Cursor cursor = myDB.query("user", new String[] { "id_user,phone,password,fbtoken" },
null, null, null, null, null,null);

if (cursor.moveToFirst()) {
do {
user_id_pass.add(cursor.getString(0));
user_id_pass.add(cursor.getString(1));
user_id_pass.add(cursor.getString(2));
user_id_pass.add(cursor.getString(3));

} while (cursor.moveToNext());
}
if (cursor != null && !cursor.isClosed()) {
cursor.close();
}

}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}

return user_id_pass;
}

//--------delete values from database----------
public void deleteAll()
{
try{
All_data.database_category="";
myDB = this.getWritableDatabase();
String deletecitydata = "Delete FROM CITIES";
String deleteCATEGORIESdata = "Delete FROM CATEGORIES";
String deleteCOMPANIESdata = "Delete FROM COMPANIES";
String deleteMAIN_TABLEdata = "Delete FROM MAIN_TABLE";
String deleteCOMMENTSdata = "Delete FROM COMMENTS";
String deleteLIKECOMMENTSdata = "Delete FROM LIKECOMMENTS";
String deleteUserData = "Delete FROM user";
String initializeUser = "INSERT INTO user (id_user, phone, password, scancontact, fbtoken, comments_updated, companies_updated ) values ('','','','yes','', '20110301000000','20110301000000' ) ";
myDB.execSQL(deletecitydata);
myDB.execSQL(deleteCATEGORIESdata);
myDB.execSQL(deleteCOMPANIESdata);
myDB.execSQL(deleteMAIN_TABLEdata);
myDB.execSQL(deleteCOMMENTSdata);
myDB.execSQL(deleteLIKECOMMENTSdata);
myDB.execSQL(deleteUserData);
myDB.execSQL(initializeUser);
} catch(Exception er)
{
er.printStackTrace();

}




}

//------update user table in database----------------
public void updatelogin(String mIdUser, String mPhone, String mPassword, String mFBToken )
{
myDB = this.getWritableDatabase();

if (mPhone == null || mPhone == "null") {
mPhone="";
}

if (mPassword == null || mPassword == "null") {
mPassword="";
}

String insertcitydata = "update user set id_user='"+mIdUser+"',phone='"+mPhone+"',password= '"+mPassword+"',fbtoken='"+mFBToken+"',scancontact ='yes'";
// String insertcitydata = "insert into CITIES(ID_CITY,comune) values (?,?)";
myDB.execSQL(insertcitydata);
}

zalani is offline  
Reply With Quote
Sponsors
Reply

Bookmarks


Go Back   Android Forums > Android Development > Application Development User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 12:12 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo