SQLDroid 是 Android 平台上的 SQLite 数据库的 JDBC 驱动程序
来源:互联网 发布:淘宝卖家上传图片3m 编辑:程序博客网 时间:2024/05/17 08:07
// 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();
}
- SQLDroid 是 Android 平台上的 SQLite 数据库的 JDBC 驱动程序
- Android平台下的数据库SQLite
- 常用数据库的驱动程序及JDBC URL
- 常用数据库的驱动程序及JDBC
- 常用数据库的驱动程序及JDBC URL
- 常用数据库的驱动程序及JDBC URL:
- 常用数据库的驱动程序及JDBC URL
- 常用数据库的驱动程序及JDBC URL
- 常用数据库的驱动程序及JDBC URL
- 常用数据库的JDBC驱动程序写法
- 常用数据库的驱动程序及JDBC
- android平台上关于SQLite帮助类SQLiteOpenHelper 的使用
- sqlite-jdbc在eclipse上的使用
- sqlite jdbc 访问resource下的数据库
- JDBC驱动程序的类型
- SQLSERVER2000的jdbc驱动程序
- JDBC驱动程序的类型
- SQLSERVER2000的jdbc驱动程序
- 面向对象思想
- 使用PhpDocument生成帮助文档说明
- 关于Flex中的LoaderInfo
- EJB3.0总结上
- 为我加油把
- SQLDroid 是 Android 平台上的 SQLite 数据库的 JDBC 驱动程序
- Ping域名出现“Ping request could not find host”信息
- 流媒体资料
- EJB3.0总结下(转)
- 构造TPtr方法总结
- 学习Objective-C:入门手册
- 最近好忙
- linux下vsftp和samba基础配置
- 甩饼歌