Andtoid使用Sqlite创建数据库的示例代码
时间: 2024-04-29 09:24:44 浏览: 12
Sure, here's an example code for creating a database on Android using SQLite:
```
public class DatabaseHelper extends SQLiteOpenHelper {
// Database Version
private static final int DATABASE_VERSION = 1;
// Database Name
private static final String DATABASE_NAME = "sample_database";
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {
// create notes table
db.execSQL(Note.CREATE_TABLE);
}
// Upgrading database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS " + Note.TABLE_NAME);
// Create tables again
onCreate(db);
}
}
```
Note: This code is just a sample code and may not work in your specific case. You should modify this code based on your specific requirements.