SqliteDB 操作数据库
2015-09-12 22:11
375 查看
SqliteDB 操作数据库
创建并获取数据
第一个参数是-->sql: the SQL query. The SQL string must not be ; terminated 第二个参数是-->selectionArgs: You may include ?s in where clause in the query, which will be replaced by the values from selectionArgs. The values will be bound as Strings.
如果想得到相应列名对应的列那么需要使用:
cursor.getColumnIndex("_id")
如果想要获取数据库中相应类型的值那么需要使用如下方式
int—>cursor.getInt(相应的列的位置即上面的那个语句获取的值)
String—>cursor.getString(同上)
要注意的是如果列对应的值类型不匹配或者是空那么就会出现异常
对数据进行增删改操作
db.execSQL("insert into student values(?,?,?,?,?)",newObject[]{4,"liuneng","男",58,"666"});
2.这个一会经常使用
SQLiteDatabase db = SQLiteDatabase.openDatabase(DB_PATH, null,SQLiteDatabase.OPEN_READWRITE); db.insert() Parameters: table : the table to insert the row into nullColumnHack: optional; may be null. SQL doesn't allow inserting a completely empty row without naming at least one column name. If your provided values is empty, no column names are known and an empty row can't be inserted. If not set to null, the nullColumnHack parameter provides the name of nullable column name to explicitly insert a NULL into in the case where your values is empty. values: this map contains the initial column values for the row. The keys should be the column names and the values the column values Returns: the row ID of the newly inserted row, or -1 if an error occurred
更新
db.update int android.database.sqlite.SQLiteDatabase.update(String table, ContentValues values, String whereClause, String[] whereArgs) Parameters: table the table to update in values a map from column names to new column values. null is a valid value that will be translated to NULL. whereClause the optional WHERE clause to apply when updating. Passing null will update all rows. whereArgs
删除
db.delete int android.database.sqlite.SQLiteDatabase.delete(String table, String whereClause, String[] whereArgs) Convenience method for deleting rows in the database. Parameters: table the table to delete from whereClause the optional WHERE clause to apply when deleting. Passing null will delete all rows. whereArgs Returns: the number of rows affected if a whereClau
相关文章推荐
- MySQL几种方法的数据库备份
- MySQL 导入EXCEL数据
- mysql导出查询结果到csv方法
- 关于MySQL存储过程中遇到的一个错误
- SQL优化
- SQL优化
- mysql的group by应用
- sql server 分页查询以及区间查询
- Python调用SqlPlus查询Oracle
- PostgreSQL空间数据库
- MongoDB简单概述
- mysql参数记录
- Ubuntu中安装及配置postgreSQL
- postgresql在ubuntu下安装
- [Database] redis 和 memcached的区别
- SQL Server数据库镜像的页面自动修复原理
- Linux系统下Memcached缓存集群和magent代理服务器集群测试方案
- Linux系统下memcached代理服务器magent离线安装手册
- Linux系统下memcached离线安装手册
- MySQL常用语句