SQLite数据库处理与Android应用 [英] SQLite database handling with android application
本文介绍了SQLite数据库处理与Android应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要创建一个 SQLite数据库
和插入记录。但我的数据库没有创建。
以下是code。无法理解为什么。尝试这种很长一段时间
如果有人能帮助它是一个很大的帮助。
公共类DatabaseHelper扩展SQLiteOpenHelper {
静态最后弦乐DBNAME =MyDatabase的;
公共DatabaseHelper(上下文的背景下){
超(背景下,数据库名,NULL,33);
}
@覆盖
公共无效的onCreate(SQLiteDatabase DB){
字符串QRY =CREATE TABLE DEPT(DEPT_ID INTEGER PRIMARY KEY,DEPTNAME文本);
db.execSQL(QRY);
}
}
我打电话这样的构造
公共类MainActivity延伸活动{
/ **第一次创建活动时调用。 * /
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
DatabaseHelper DP =新DatabaseHelper(本);
Toast.makeText(这一点,执行完成,Toast.LENGTH_LONG).show();
}
}
解决方案
通过使用此示例创建数据库 http://marakana.com/forums/android/examples/55.html
Hi i am going to create a SQLite database
and insert records. but my database does not create.
following is the code. Cant understand why. trying this for a long time
If someone can help its a great help
public class DatabaseHelper extends SQLiteOpenHelper{
static final String dbName="MyDatabase";
public DatabaseHelper(Context context) {
super(context, dbName, null,33);
}
@Override
public void onCreate(SQLiteDatabase db) {
String qry = "CREATE TABLE DEPT(dept_id INTEGER PRIMARY KEY, deptName TEXT)";
db.execSQL(qry);
}
}
I am calling the constructor like this
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
DatabaseHelper dp = new DatabaseHelper(this);
Toast.makeText(this, "Finish Execution", Toast.LENGTH_LONG).show();
}
}
解决方案
create your database by using this sample http://marakana.com/forums/android/examples/55.html
这篇关于SQLite数据库处理与Android应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文