测试文章发布

100%


提示

警告
测试_demo4

http://www.bilibili.com


public class ShoppingDBHelper extends SQLiteOpenHelper {

    private static final String DB_NAME = “shopping.db”;

标签

private static final String TABLE_NAME_Good_info = “good_info”;

private static final String TABLE_NAME_cart_info = “cat_info”;

    private static final int version = 2;

@Override

    public void onCreate(SQLiteDatabase db) {

        //创建数据库sql语句并执行

        String sql = “create table if not exists good_info” +

                “(id integer primary key autoincrement,” +

                “name varchar(100),price varchar(20)” +

                “,freeShippingInfo varchar(20),commentCount varchar(20)” +

                “,storeName varchar(20),image integer)”;

        db.execSQL(sql);

    String sql1 = “create table if not exists cart_info” +

            “(id integer primary key autoincrement,” +

            “good_name varchar(100) not null,count integer ” +

            “not null,price varchar(20),image integer)”;

    db.execSQL(sql1);;

    }

    @Override


    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }

    public long insertgoodsinfo(ArrayList<Product> list) {

        long result = 0;

        try {

            mWDB.beginTransaction();

            for (Product product : list) {

                ContentValues values = new ContentValues();

                values.put(“name”, product.getName());

                values.put(“price”, product.getPrice());

                values.put(“freeShippingInfo”, product.getFreeShippingInfo());

                values.put(“commentCount”, product.getCommentCount());

                values.put(“storeName”, product.getStoreName());

                values.put(“image”, product.getImage());

                result = mWDB.insert(“good_info”, null, values);

            }

            mWDB.setTransactionSuccessful();

        } catch (Exception e) {

            e.printStackTrace();

        } finally {

            mWDB.endTransaction();

        }

        return result;

    }

    //把商品的数量和名字的信息添加到数据库的cart_info表

public void addCartInfo(goodCartInfo cartInfo) {

    SQLiteDatabase db = null;

    try {

        db = getWritableDatabase();

        ContentValues values = new ContentValues();

        values.put(“count”,cartInfo.getCount());

        values.put(“good_name”,cartInfo.getGood_name());

        values.put(“price”,cartInfo.getGood_price());

        values.put(“image”,cartInfo.getGood_image());

        db.insert(“cart_info”, null, values);

    } catch (SQLException e) {

        e.printStackTrace();

    }

    }

    public void updateCartInfoCount(String good_name, int count) {

    SQLiteDatabase db = null;

    try {

        db = getWritableDatabase();

        ContentValues values = new ContentValues();

        values.put(“count”, count);

        db.update(“cart_info”, values, “good_name” + ” = ?”, new String[]{good_name});

    } catch (SQLException e) {

        e.printStackTrace();

    }

}

    public ArrayList<Product> queryAllGoodsinfo() {

        ArrayList<Product> list = new ArrayList<>();

        String sql = “select * from good_info”;

        Cursor cursor = mRDB.rawQuery(sql, null);

        while (cursor.moveToNext()) {

            Product product = new Product(cursor.getInt(6), cursor.getString(1),

                    cursor.getString(2),cursor.getString(3),

                    cursor.getString(4),cursor.getString(5));

            list.add(product);

        }

        cursor.close();

        return list;

    }

    public ArrayList<goodCartInfo> queryAllCartGoodsinfo() {

        ArrayList<goodCartInfo> list = new ArrayList<>();

        SQLiteDatabase db=getReadableDatabase();

        String sql = “select*from cart_info”;

        Cursor cursor = mRDB.rawQuery(sql, null);

        while (cursor.moveToNext()) {

          goodCartInfo cartInfo1 = new goodCartInfo();

          cartInfo1.setGood_name(cursor.getString(1));

          cartInfo1.setCount(cursor.getInt(2));

          cartInfo1.setGood_price(cursor.getString(3));

          cartInfo1.setGood_image(cursor.getInt(4));

            list.add(cartInfo1);

        }

        return list;

    }

    public void deleteCartInfoByGoodName(String good_name) {

        SQLiteDatabase db = null;

        try {

            db = getWritableDatabase();

            db.delete(“cart_info”, “good_name” + ” = ?”, new String[]{good_name});

        } catch (SQLException e) {

            e.printStackTrace();

        }

    }

}

评论

  1. 王凯
    Linux SamsungBrowser
    2 年前
    2023-11-27 20:08:54

    测试

    • 王凯
      王凯
      Linux SamsungBrowser
      2 年前
      2023-11-27 20:17:42

      你好

  2. 博主
    Macintosh Edge
    2 年前
    2023-11-27 21:03:09

    你好

  3. wkai869
    Android SamsungBrowser
    2 年前
    2023-11-27 23:10:28

    teat

  4. 正异新
    Android Chrome
    2 年前
    2023-11-27 23:48:57

    6666666666

  5. 777
    Windows Chrome
    2 年前
    2023-11-27 23:51:33

    老铁牛逼666

  6. Alex
    Windows Edge
    2 年前
    2023-11-28 8:45:02

    ceshi.pinglun

  7. 牛牛牛
    Windows Edge
    2 年前
    2023-11-28 9:08:29

    66666

  8. sdasd
    Windows Edge
    2 年前
    2023-11-28 10:33:36

    ?id=1

  9. 博主
    Macintosh Safari
    2 年前
    2023-11-28 16:07:25

    ceshi1

发送评论 编辑评论


|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
下一篇