About the Android SQLite database

Source: Internet
Author: User
Tags sqlite database

Adding Data methods

Sqlitehepler Hepler = new Sqlitehepler (details_activity.this);
Sqlitedatabase db = Hepler.getwritabledatabase ();
Contentvalues values = new Contentvalues ();
Values.put ("id", list_d.id);
Values.put ("Ima", List_d.pic.get (0));
Values.put ("Mar_price", List_d.limitprice);
Values.put ("Shop_price", List_d.price);
Values.put ("title", List_d.name);
Db.insert (Sqlitehepler.table_name_user, null, values);


Toast.maketext (Details_activity.this, "added Favorites", Toast.length_short). Show ();
De_collect.setbackgroundresource (r.drawable.head_button_selected);

Querying data methods


List_c = new arraylist<car_vo> ();
Cursor C = Db.query (false, sqlitehepler.table_name_user, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
while (C.movetonext ()) {

String sid = C.getstring (C.getcolumnindex ("id"));
String Sima = c.getstring (C.getcolumnindex ("ima"));
String Sshop_price = c.getstring (C.getcolumnindex ("Shop_price"));
String stitle = c.getstring (C.getcolumnindex ("title"));

Car_vo = new Car_vo ();

Car_vo.setid (SID);
Car_vo.setima (Sima);
Car_vo.setprice (Sshop_price);
Car_vo.setname (Stitle);

List_c.add (CAR_VO);
LOG.I ("Shop", Car_vo.tostring ());

Build a Table statement

Package Com.example.administrator.redbaby_9s.view;

Import Android.content.Context;
Import Android.database.sqlite.SQLiteDatabase;
Import Android.database.sqlite.SQLiteOpenHelper;

public class Sqlitehepler extends Sqliteopenhelper {
public static final String Table_name_user = "Shopuser";

public static final String Table_name_login = "Loginuser";

public static final String sqlite_database_name = "mydb.db";
public static final int sqlite_database_version = 1;
public static final String Table_name_user = "USER";

Public Sqlitehepler (Context context) {
Super (context, sqlite_database_name, NULL, sqlite_database_version);
TODO auto-generated Constructor stub
}

@Override
public void OnCreate (Sqlitedatabase db) {
String sqlcreatestr = "CREATE TABLE" + Table_name_user + "("
+ "_id INTEGER PRIMARY KEY autoincrement,"
+ "ID varchar (100),"
+ "ima varchar (100),"
+ "Mar_price varchar (100),"
+ "Shop_price varchar (100),"
+ "title varchar (100)" + ")";

Db.execsql (SQLCREATESTR);


String sql_shop = "CREATE TABLE" + Table_name_user + "("
+ "_id INTEGER PRIMARY KEY autoincrement,"
+ "ID varchar (100),"
+ "ima varchar (100),"
+ "Shop_price varchar (100),"
+ "title varchar (100)"
+ ")";


Db.execsql (Sql_shop);


String sql_login = "CREATE TABLE" + Table_name_login + "("
+ "_id INTEGER PRIMARY KEY autoincrement,"
+ "name varchar (100),"
+ "pass varchar (100)"
+ ")";


Db.execsql (Sql_login);
}

@Override
public void Onupgrade (sqlitedatabase db, int oldversion, int newversion) {

}

}

About the Android SQLite database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.