android中用cursor游标取数据库数据

android中用cursor游标取数据库数据,第1张

把读取的数据存起来就可以了~

ArrayList<HashMap<String, Object>> temp = new ArrayList<HashMap<String,Object>>()

if(cursor.moveToFirst()){

    do{

        HashMap<String, Object> map = new HashMap<String, Object>()

        String name = cursor.getString(cursor.getColumnIndex("fromuser"))

        String toname = cursor.getString(cursor.getColumnIndex("touser"))

String content = cursor.getString(cursor.getColumnIndex("content"))

        String date = cursor.getString(cursor.getColumnIndex("date"))

        String type = cursor.getString(cursor.getColumnIndex("type"))

        map.put("fromuser", name) 

        //其他数据同 

        temp.add(map)

    }while(cursor.moveToNext())

}

//读取数据

String name1 = temp.get(1).get("name").toString()

虽然我没怎么看

懂你

的意思。单给你集中方法依次输出:

1:你可以在便利数据库的时候,加上可滚动的

结果集

属性。这样基本上可以任意的 *** 作

数据库数据

Statement

st

=

connection

.createStatement(ResultSet.TYPE_SCROLL_

SENSITIVE

,

ResultSet.CONCUR_UPDATABLE)

ResultSet

rs

=

st.executeQuery(sql)

2:你也可以把数据库里面的所有数据读取到一个集合中,比如List中,遍历的时候更加方便,可以任意的 *** 作。

比如把你的ID、name以对象user放入到一个集合list中。

建议使用集合,因为java基本上所有的 *** 作都是面向对象的 *** 作。

declare

cursor c_dept is select * from table1

where serv_id in (select serv_id from zy_th)

and org_trm_id=0

row_dept c_dept%rowtype

begin

open c_dept

loop

fetch c_dept into row_dept

If c_dept%notfound Then

Exit

End If

Insert Into table2 value row_dept

commit--在这加个提交,插入一条提交一次就OK

end loop

close c_dept

end


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/10029676.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-04
下一篇 2023-05-04

发表评论

登录后才能评论

评论列表(0条)

保存