从Sql数据库到数组的数据(Data from Sql Database to an Array)

编程入门 行业动态 更新时间:2024-10-07 16:20:09
从Sql数据库到数组的数据(Data from Sql Database to an Array)

我想把一些来自Sql数据库的数据放在一个数组中

这是我的数组代码:

openDB(); Cursor c = myDb.getSpalte(); while (!c.isAfterLast()) { s1nInt[i] = c.getInt(1); i++; c.moveToNext(); } c.close(); closeDB();

这是我的getSpalte();代码getSpalte(); 方法:

public Cursor getSpalte() { String where= null; Cursor c = db.query(true, DATABASE_TABLE, KEY_KALOA, where, null, null, null, null, null); if (c != null) { c.moveToFirst(); } return c; }

如果我运行这个我得到这些例外:

06-27 13:34:01.021: E/CursorWindow(24334): Failed to read row 0, column 1 from a CursorWindow which has 1 rows, 1 columns.

现在我得到了这些命令的异常:

Number[] series2Numbers = {/*s1nInt[i-6],s1nInt[i-5],s1nInt[i-4],s1nInt[i-3],s1nInt[i- 2],s1nInt[i-1],*/s1nInt[i]};

这是我的例外:

Graph.onStart() line: 75 Graph(Fragment).performStart() line: 1801 FragmentManagerImpl.moveToState(Fragment, int, int, int, boolean) line: 937 FragmentManagerImpl.moveToState(int, int, int, boolean) line: 1106 BackStackRecord.run() line: 690 FragmentManagerImpl.execPendingActions() line: 1571 FragmentManagerImpl$1.run() line: 447 Handler.handleCallback(Message) line: 733

I would like to put some data from a Sql database in an Array

Here is my code for the array:

openDB(); Cursor c = myDb.getSpalte(); while (!c.isAfterLast()) { s1nInt[i] = c.getInt(1); i++; c.moveToNext(); } c.close(); closeDB();

And here is my code for the getSpalte(); Method:

public Cursor getSpalte() { String where= null; Cursor c = db.query(true, DATABASE_TABLE, KEY_KALOA, where, null, null, null, null, null); if (c != null) { c.moveToFirst(); } return c; }

And if I run this I get these Exception:

06-27 13:34:01.021: E/CursorWindow(24334): Failed to read row 0, column 1 from a CursorWindow which has 1 rows, 1 columns.

now I got for these command an exception:

Number[] series2Numbers = {/*s1nInt[i-6],s1nInt[i-5],s1nInt[i-4],s1nInt[i-3],s1nInt[i- 2],s1nInt[i-1],*/s1nInt[i]};

This is my Exception for this:

Graph.onStart() line: 75 Graph(Fragment).performStart() line: 1801 FragmentManagerImpl.moveToState(Fragment, int, int, int, boolean) line: 937 FragmentManagerImpl.moveToState(int, int, int, boolean) line: 1106 BackStackRecord.run() line: 690 FragmentManagerImpl.execPendingActions() line: 1571 FragmentManagerImpl$1.run() line: 447 Handler.handleCallback(Message) line: 733

最满意答案

游标从0开始,在访问数据之前必须移动到第一行:

while(c.moveToNext()) { s1nInt[i] = c.getInt(1); i++; }

The cursor starts at 0 and must be moved to the first row before accessing data:

while(c.moveToNext()) { s1nInt[i] = c.getInt(1); i++; }

更多推荐

本文发布于:2023-04-29 08:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1335584.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   数据库   数据   Sql   Database

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!