1 Star 0 Fork 0

mybrion / SQLDroid

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Build Status

SQLDroid

SQLDroid is a JDBC driver for Android's sqlite database (android.database.sqlite.SQLiteDatabase) originally conceived by Kristian Lein-Mathisen. See http://sqldroid.org/.

SQLDroid lets you access your app's database through JDBC. Android ships with the necessary interfaces needed to use JDBC drivers, but it does not officially ship with a driver for its built-in SQLite database engine. When porting code from other projects, you can conveniently replace the JDBC url to jdbc:sqlite to access an SQLite database on Android.

The SQLDroid JAR with the JDBC driver for Android is 33KB. We also offer a RubyGem "sqldroid" for use with Ruboto.

Community

Download

You can use SQLDroid in you maven project by declaring this dependency:

<dependency>
    <groupId>org.sqldroid</groupId>
    <artifactId>sqldroid</artifactId>
    <version>1.0.3</version>
</dependency>

Or if you're using gradle:

compile 'org.sqldroid:sqldroid:1.0.3'

Binary distributions are available for download from the Maven Central Repository: http://search.maven.org/#search%7Cga%7C1%7Csqldroid

Usage

Here is a minimal example of an Android Activity implemented in Java with SQLDroid.

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.SQLException;

public class MainActivity extends AppCompatActivity {

    private Connection connection;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        try {
            DriverManager.registerDriver((Driver) Class.forName("org.sqldroid.SQLDroidDriver").newInstance());
        } catch (Exception e) {
            throw new RuntimeException("Failed to register SQLDroidDriver");
        }
        String jdbcUrl = "jdbc:sqldroid:" + "/data/data/" + getPackageName() + "/my-database.db";
        try {
            this.connection = DriverManager.getConnection(jdbcUrl);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void onDestroy() {
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
        super.onDestroy();
    }
}

You can find an example of how to use SQLDroid with ActiveRecord on Ruboto here:

https://github.com/ruboto/ruboto/wiki/Tutorial%3A-Using-an-SQLite-database-with-ActiveRecord

Debug output

You can set the SQLDroid log output level like this

org.sqldroid.Log.LEVEL = android.util.Log.VERBOSE;

You can turn on resultset dumps like this

org.sqldroid.SQLDroidResultSet.dump = true;

Building

The SQLDroid JAR file is a straight collection of the compiled classes. If you have Ruby installed, you can generate the JAR using

rake jar

To make a gem for use with Ruboto run

rake gem

To release the gem to rubygems.org (requires permissions on rubygems.org) run

rake release

Building with mvn

SQLDroid is a normal Maven project. If you have Android 21 installed (sdkmanager --install platforms;android-21), you can generate the JAR using

mvn install

To release the jar to Maven Central (requires permissions and a PGP key) first tag the release version

mvn -Prelease release:prepare

Then deploy the artifact to Maven Central

mvn -Prelease release:perform

The MIT License (MIT) Copyright (c) 2009 SQLDroid Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
Java 等 2 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/mybrion/SQLDroid.git
git@gitee.com:mybrion/SQLDroid.git
mybrion
SQLDroid
SQLDroid
master

搜索帮助