What types of Databases are available in Android?
Hi all can anyone say why I should use an SQLite database for 开发者_JAVA技巧my mobile application? Are there any databases instead that I can use?
SQLite database is the way to go :-)
smashing magazine posted a nice article about it last week
http://www.smashingmagazine.com/2011/03/28/get-started-developing-for-android-with-eclipse-reloaded/
Another option is Berkeley DB, which like SQLite is a lightweight, fast, reliable database library. You have a few different options of how you can use Berkeley DB on Android:
- Use Berkeley DB via the SQL API as an upgrade/replacement for SQLite. The BDB SQL API is completely SQLite compatible, so your SQLite application should be able to convert to using Berkeley DB very easily. Why would you want to use Berkeley DB instead of SQLite? On Android, it's mostly about concurrency. BDB supports concurrent read and write operations. If your Android application needs that, then BDB is an excellent option. On non-Android platforms, BDB scalability, performance, HA and enterprise Support make it an attractive alternative for applications either using SQLite already or considering using it. There's a useful discussion on OTN about using the BDB SQL API on Android here.
- Use Berkeley DB via the key-value API as a simple, local data store.
- Use Berkeley DB Java Edition via the key-value, Java Collections or Direct Persistence Layer APIs to manage application data within a pure Java environment. Here's an interesting Blog entry about using Berkeley DB JE on Android.
Disclaimer: I'm the Product Manager for Berkeley DB. That said, we think that SQLite is a great product (we're part of the SQLite Consortium) and we're happy to see people adopting and using it. There are situations where Berkeley DB may be a better choice, hence my suggestion here.
It's generally accepted that SQLite is the best database platform for Android because it's light weight nature lends itself nicely to mobile devices where processing power and memory are limited.
That's not to say that you couldn't do it, at the end of the day it's Java. You could write your own, or find open source code, that would enable you to use another database. The problem there is that the phone would also have to have a database daemon to handle the requests whereas in SQLite the database is a file stored on the phone and so can easily be accessed in Java.
At the end of the day it would be silly to try and run a MySQL daemon for example on a phone because I very much doubt it'd have the memory to cope. You'd be much better of getting used to SQLite because it's a very flexible and popular database platform.
As mentioned in another answer, you can cross-compile Berkeley DB for Android and use the Java Bindings, including it as an .so native library within your .apk (comes out packed at ~710k). There is a step-by-step guide here (since it requires minor tweaking).
You can also use the DB4O database. For more help you can check out their website. http://www.db4o.com/(S(tqvrulmp3ybmtw55i3mgop55))/Android/default.aspx
精彩评论