Android平台的SQLite驱动 SQLDroid

码农软件 · 软件分类 · 手机开发包 · 2019-05-07 11:44:28

软件介绍

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();
}

本文地址:https://codercto.com/soft/d/5211.html

知识发现

知识发现

史忠植 / 2011-1 / 59.00元

《知识发现(第2版)》全面而又系统地介绍了知识发现的方法和技术,反映了当前知识发现研究的最新成果和进展。全书共分15章。第1章是绪论,概述知识发现的重要概念和发展过程。下面三章重点讨论分类问题,包括决策树、支持向量机和迁移学习。第5章阐述聚类分析。第6章是关联规则。第7章讨论粗糙集和粒度计算。第8章介绍神经网络,书中着重介绍几种实用的算法。第9章探讨贝叶斯网络。第10章讨论隐马尔可夫模型。第11章......一起来看看 《知识发现》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

html转js在线工具
html转js在线工具

html转js在线工具