Android database, androiddatabase

Source: Internet
Author: User

Android database, androiddatabase

In front of the database, all databases are executed directly, db.exe cute ().


Today, I learned another logic from the source code of company 1.0,

SecureSQLiteDatabase db = null;

Try {

Db = mOpenHelper. openDatabase ();


Db. beginTransaction ();

Try {

Todo Data Operations

};

// Operations to be performed on the database

Db. update (MstDataEntry. TABLE_NAME, values, whereClause, whereArgs );


Db. setTransactionSuccessful ();

} Finally {

Db. endTransaction ();

}

} Finally {

MOpenHelper. close ();

}


When the program executes the endTransaction () method, it checks whether the transaction flag is successful,

If the setTransactionSuccessful () method is called before the program is executed to endTransaction () and the transaction flag is set to successful, the transaction is committed,

If the setTransactionSuccessful () method is not called, the transaction is rolled back.

In this way, the operation we want to execute, that is, the transaction is determined to be executed, and the db is turned off.



High reward for android database Packaging

I earned points.
In fact, it is very easy to give you a basic database class. You can inherit it, and then you can create your own database on the SD card. Haha

You gave me a lot of points. Wow.
Attachments cannot be uploaded... Code directly ..

Package sean. data;

Import java. io. File;

Import sean. configs. Const;

Import android. content. Context;
Import android. database. sqlite. SQLiteDatabase;
Import android. database. sqlite. SQLiteException;
Import android. database. sqlite. SQLiteDatabase. CursorFactory;
Import android. OS. Environment;
Import android. util. Log;

Public abstract class SDSQLiteOpenHelper {
Private static final String TAG = SDSQLiteOpenHelper. class. getSimpleName ();

// @ SuppressWarnings ("unused ")
// Private final Context context;
Private final String dbName;
Private final CursorFactory factory;
Private final int newVersion;
Private String dbPath = Const. DBPath;

Private SQLiteDatabase sdDatabase = null;
Private boolean isInitializing = false;

/**
* Create a helper object to create, open, and/or manage a database.
* Database is not actually created or opened until one
* {@ Link # getWritableDatabase} or {@ link # getReadableDatabase} is called.
*
* @ Param context
* To use to open or create the database
* @ Param name
* Of the database file, or null for an in-memory database
* @ Param factory
* To use for creating cursor objects, or null for the default
* @ Param version
* Number of the database (starting at 1); if the database is
* Older, {@ link # onUpgrade} will be used to upgrade the database
* & # Other full texts>
 
Android eclipse database usage

Most databases on the Android platform are encapsulated using ContentProvider.
We recommend that you take a look at the content about ContentProvider In the SDK documentation.
In addition, we recommend that you refer to the example of a Provider in the sample code under the SDK.

Below are some simple answers to your questions:
1. Is this data warehouse A. txt or something like mysql?
Databases on the Android platform encapsulate and streamline SQL statements. SQLite.
The basic operations (query, insert, change and delete) are the same as those in SQL.
After your program runs once, a *. db file is generated under the "installation directory" of your application.
For example, the package name of your application is zhidao.baidu.com.
The database file is in the following path.
/Data/zhidao.baidu.com/databases/xxx.db
The file name is specified in ContentProvider.

2. Where can I see the contents of this database and table?
At the same time, we recommend a tool named SQLite Browser for you to access the Internet.
Both windows and Linux are available. You can intuitively view the content in the db file,
Since you are familiar with mysql, this is even more difficult.

3. How can I associate my database classes with db. java and a. java, B. java, and c. java?
On the Android platform, If you inherit ContentProvider and write a class to operate the database,
Then you need to declare the database in the AndroidManifese. xml file
One important thing about the database declaration is its authorities.
This authorities is the virtual path you specify for the newly created database.
Its naming method is similar to that of the package name.
Developers must ensure its uniqueness.
Other a. java, B. java, and c. java databases can be found through the path you declare.
Even if files a, B, and c are files in another application, they can be accessed.
It is like you specify the mysql DATA address, no matter which PHP file you are in, you can try to access this mysql database

So much.
We recommend that you take a look at the examples in the sample code under the SDK, which contains many basic examples.

200 points or more. Don't forget to add extra points ~ O_O ~
Reference: www.lephone.net

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.