SQLite数据库处理与Android应用数据库、SQLite、Android

由网友(等风也等你)分享简介:我要创建一个 SQLite数据库和插入记录。但我的数据库没有创建。以下是code。无法理解为什么。尝试这种很长一段时间如果有人能帮助它是一个很大的帮助。公共类DatabaseHelper扩展SQLiteOpenHelper {静态最后弦乐DBNAME =MyDatabase的;公共DatabaseHelper(上下文...

我要创建一个 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();

}
}
 
Android SQlite数据库 SQLiteOpenHelper类

解决方案

通过使用此示例创建数据库 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

阅读全文

相关推荐

最新文章