android sqlite驱动包,SQLDroid-Android平台的SQLite驱动

SQLDroid 是 Android 平台上的 SQLite 数据库的 JDBC 驱动程序。

示例代码:

// your datapath is /data/data/$package/

// e.g. "/data/data/com.lemadi.robotanks.android"

// note that if you want to put it in $datapath/databases/

// the way Activity.openOrCreateDatabase does it,

// you have to create the databases subfolder if not already there

String url = "jdbc:sqldroid:" + getDataPath() + "/main.sqlite";

Connection con = DriverManager.getConnection(url);

con.createStatement().execute("CREATE TABLE MYTABLE (id INT, name CHAR(200))");

try {

con.createStatement().execute("CREATE TABLE MYTABLE (id INT, name CHAR(200))");

con.createStatement().execute("CREATE TABLE HIGH_SCORES (level VARCHAR, name CHAR, time INT, timestamp INT)");

} catch (SQLException e1) {

System.out.println("error creating table: i guess they were already there");

}

con.createStatement().execute("INSERT INTO MYTABLE (id, name) VALUES (100, 'klm')");

PreparedStatement ps = con.prepareStatement("INSERT INTO MYTABLE (id, name) VALUES (?, ?)");

ps.setInt(1, (int)(Math.random() * 100));

ps.setString(2, "you're " + new Integer((int)(Math.random()*1000)).toString() + " years old.");

ps.executeUpdate();

ResultSet rs = con.createStatement().executeQuery("SELECT id, name FROM MYTABLE ORDER BY name");

while(rs.next()) {

System.out.println("test row: " + rs.getInt(1) + " = " + rs.getString(2));

System.out.println("test row string: " + rs.getInt("id") + " = " + rs.getString("name"));

}

rs.close();

// this method demonstrates the limited Metadata functionality:

private static boolean tableExists(String tableName) {

ResultSet rs = con.getMetaData().getTables(null, null, tableName, null);

// rs.next() returns true is there is 1 or more rows

return rs.next();

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值