Android: Creating SQLite databases and creating databases on SD cards (1)

Source: Internet
Author: User

1. MOBILE/data/ApplicationsProgramCreate a database under the package name/directory

If the size of the created database is small, you can use the sqliteopenhelper class that comes with Android to directly generate the database on the mobile phone

/Data/application package name/directory. The method is as follows:

Write a mysqliteopenhelper class that inherits from the sqliteopenhelper class and overwrites the oncreate and onupdate methods.

Public class mydatabasehelper extends mysqliteopenhelper {

// Database Name

Public final static string database_name = "DB ";

// Database version

Public final static int database_version = 1;


Mydatabasehelper (final context ){
Super (context, database_name, null, database_version );
}


@ Override
Public void oncreate (sqlitedatabase dB ){
// Create a database table
}

@ Override
Public void onupgrade (sqlitedatabase dB, int oldversion, int newversion ){

If (newversion! = Oldversion ){


// Update the database

}
Oldversion = newversion;
}
}

However, the database generated using this method is saved in the/data folder of the mobile phone, which brings two problems: 1. If the storage of the mobile phone itself

The size of the created database is limited when the space is small. 2. If the root permission of the mobile phone cannot be obtained, the created database cannot be directly viewed.

File. Given the above problems, it is a good choice to put the database on the memory card.

NextArticleThis section describes how to create a database on a memory card.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.