关于创建一个简单的SQLite数据库

时间:2015-06-27 03:41:39

标签: android sqlite

$pdo->beginTransaction();

// Prepare the first statement
$stmt = $pdo->prepare('INSERT INTO posts (title, text, user, club, time) VALUES (:title, :text, :user, :club, :time)');
// Execute the statement with an array of bound values
$stmt->execute(array(':title' => $title, ':text' => $text, ':user' => $user, ':club' => $club, ':time' => $time));

// Prepare & execute the second one
$stmt = $pdo->prepare('INSERT INTO post_likes (user, post)  VALUES (:name, :post)');
$stmt->execute(array(':name' => $name, ':post' => $pdo->lastInsertId()));

// Commit it
$pdo->commit();
public class MyDataBaseHelper extends SQLiteOpenHelper{

    public static final String CREATE_BOOK = "creat table book ("
            + "id integer primary key autoincrement, "
            + "author text, "
            + "price real, "
            + "pages integer, "
            + "name text)";

    private Context mContext;

    public MyDataBaseHelper(Context context,String name,CursorFactory factory,int version)
    {   
        super(context ,name, factory, version );
        mContext = context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

        db.execSQL(CREATE_BOOK);
        Toast.makeText(mContext,"Creat succeeded",Toast.LENGTH_SHORT).show();
    }

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


    }
}

示例只有一个按钮"创建数据库"但是当我点击按钮时,它被打破了。我不知道什么是错的,我之前从未学过SQL,那些上面的代码来自book.Did我想念一些东西?或者我的代码有什么问题?谢谢。

2 个答案:

答案 0 :(得分:2)

除非你在这里输入它是一个错字 - 你拼写"创建"错

答案 1 :(得分:1)

请编写像

这样的创建查询
public static final String CREATE_BOOK = "create table book ("
        + "id integer primary key autoincrement, "
        + "author text, "
        + "price real, "
        + "pages integer, "
        + "name text)";