如何在Android上多次有效地查询sqlite数据库(How to efficiently query sqlite database multiple times on Android)
对于我的应用程序,我需要查询sqlite数据库大约40-50次。 我确信我写的代码效率很低。 不幸的是,我找不到很多涉及多次查询数据库的在线示例。
String[] entryValArray = new String[indicesList.size()]; DBHelper dbHelper = new DBHelper(MainActivity.context); SQLiteDatabase db = dbHelper.getReadableDatabase(); for (int i = 0; i < indicesList.size(); i++) { int moddedIndex = Integer.parseInt(indicesList.get(i), 16) % DBHelper.numEntries; String queryStr = "select * from " + DBHelper.TBL_NAME + " where " + DBHelper.IDStr + " = " + Integer.toString(moddedIndex); Cursor cursor = db.rawQuery(queryStr, null); if (cursor.moveToFirst()) entryValArray[i] = cursor.getString(1); cursor.close(); }
基本上,我正在获取字符串列表,将它们转换为十六进制值,然后修改该值以获取sqlite数据库的索引。 这是一个密码生成器应用程序。
有没有更好的方法来执行此操作,尤其是在创建游标然后在每次迭代中关闭它时。
For my application, I need to query a sqlite database around 40-50 times. I am sure that the code I wrote is very inefficient. Unfortunately, I cannot find many examples online that involves querying the database many times.
String[] entryValArray = new String[indicesList.size()]; DBHelper dbHelper = new DBHelper(MainActivity.context); SQLiteDatabase db = dbHelper.getReadableDatabase(); for (int i = 0; i < indicesList.size(); i++) { int moddedIndex = Integer.parseInt(indicesList.get(i), 16) % DBHelper.numEntries; String queryStr = "select * from " + DBHelper.TBL_NAME + " where " + DBHelper.IDStr + " = " + Integer.toString(moddedIndex); Cursor cursor = db.rawQuery(queryStr, null); if (cursor.moveToFirst()) entryValArray[i] = cursor.getString(1); cursor.close(); }
Basically, I am taking a list of strings, converting them to hex values, and then modding the value to get an index into a sqlite database. This is for a password generator application.
Is there a better way to do this, especially regarding creating a cursor and then closing it in every iteration.
原文:https://stackoverflow.com/questions/33622815
最满意答案
$('tbody').on('click', 'td', function () { var thText = $(this).closest('tbody').prev().find('th').first().text(); console.log(thText); });
table
体存储在thead
中的tbody
和header标签中。你需要找到最接近
td
tbody
而不是之前的thead
标签而不是找到它
.closest()
小提琴演示$('tbody').on('click', 'td', function () { var index = $(this).index(); var thText = $(this).closest('tbody').prev().find('th').eq(index).text(); console.log(thText); });
$('tbody').on('click', 'td', function () { var thText = $(this).closest('tbody').prev().find('th').first().text(); console.log(thText); });
table
body is stored intbody
and header tags inthead
.you need to find the closest
tbody
of thetd
and than get previousthead
tag and than findth
.closest()
Fiddle Demo$('tbody').on('click', 'td', function () { var index = $(this).index(); var thText = $(this).closest('tbody').prev().find('th').eq(index).text(); console.log(thText); });
相关问答
更多-
它看起来像是将控件拖放到表视图的顶部。 我没想到会那么容易。 放弃之前 放下后 It looks like one simply drags a control to the top of the table view. I didn't expect it to be that easy. Before Drop After Drop
-
通过单击表头来排序(Order by clicking table header)[2021-09-21]
这就是我得到的解决方案。 我在每个表头列中嵌入了一个表单。 表单包含隐藏的输入,其中包含我想要包含在$ _POST数组中的信息。 在我用于帖子的简化示例中,它只是name =“orderby”和value =“ 列名 ”。 在th标签中,我保留了onclick事件并让它调用一个允许我传递表单名称的javascript函数。 javascript函数提交表单,它将$ _POST数组传递回页面,因此我关注的所有php代码都会执行。 数组([orderby] => col_3)用于更新SQL查询中的ORDER B ... -
表头未显示(Table header is not shown)[2022-11-27]
JTableHeader需要JScrollPane作为容器 你必须从JTable获取JTableHeader并放置它,单独放置它,例如panel.add(table1.getTableHeader(), "constant, constant, constant"); ,那里使用BorderLayout作为比BoxLayout更好,更简单的JPanel LayoutManager ,例如panel.add(table1.getTableHeader(), BorderLayout.NORTH); ,然后将J ... -
jQuery滑动表头(jQuery sliding table header)[2022-02-20]
解: 使用表行上的children()方法可以更改每个元素的偏移量。 可以从offset()方法中省略left值,即 $("tr[name='headerrow']").children().offset({ top: scrollY }); Solution: Use the children() method on the table row to allow you to change the offset of each of the elements. The left val ... 隐藏一个引导表头(Hide one bootstrap table header)[2024-02-23]
正如我所评论的,也应用一个相同的类到th和那里相应的值并隐藏它们。 它会工作。 $('.hidethis').hide(); 表头操作(Table Header manipulation)[2022-08-16]
尝试: $(function() { $("a[rel='Header']").click(function () { // store the header and this for later use var $thead = $(this).parents().filter("thead").slice(0,1); var $this = $(this); // if we were sort-up - we become sort-down - otherwis ...格式化表头(Format table header)[2021-10-28]
如果使用绝对定位,则可以在页面上的任何位置放置对象。 但是为了使它们相对于表格正确定位,您需要将相对定位应用于其父元素。 所以对于这个标记:This is a heading访问表头(Accessing the Table Header)[2022-08-02]
小提琴演示 $('tbody').on('click', 'td', function () { var thText = $(this).closest('tbody').prev().find('th').first().text(); console.log(thText); }); table体存储在 thead中的 tbody和header标签中。 你需要找到最接近td tbody而不是之前的thead标签而不是找到它 .closest() .prev() 。找() 小提琴演示 ...Android表头视图(Android table header views)[2022-10-28]
我想出了如何做到这一点。 我在另一个xml文件中定义了一个View ,我得到它: View header = View.inflate(act, R.layout.table_header, null); 然后我把它变成如下的标题: list.addHeaderView(header); I figured out how to do this. I have a View defined in another xml file, and I get it like so: View header = ...垂直和水平表头(Table header on vertical and horizontal)[2022-06-05]
您始终可以使用自定义模板根据需要显示数据。 如果您需要一个具有分页,排序等功能的现有插件,我建议使用jqgrid You can always use a custom template to display the data as you wish. If you need an existing plug-in with features like Pagination, Sorting, etc. I would recommend jqgrid相关文章
更多- 用SQLite查看编辑android导出的微信聊天记录
- Mysql错误:Ignoring query to other database解决方法
- 崩溃了,android 创建表失败。。 大家看看吧。。。
- Python 在Linux中使用SQLite3
- solr delete query
- MongoDB学习 (五):查询操作符(Query Operators).1st
- sqlite怎么做多表关联。。。
- 为什么不能我的sqlite不能创建主外键关联。。。
- HTML5 Web SQL Database 数据库
- Solr 使用自定义 Query Parser
最新问答
更多- 如何检索Ember.js模型的所有属性(How to retrieve all properties of an Ember.js model)
- maven中snapshot快照库和release发布库的区别和作用
- arraylist中的搜索元素(Search element in arraylist)
- 从mysli_fetch_array中获取选定的值并输出(Get selected value from mysli_fetch_array and output)
- Windows Phone上的可用共享扩展(Available Share Extensions on Windows Phone)
- 如何在命令提示符下将日期设置为文件名(How to set file name as date in command prompt)
- 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
- 从iframe访问父页面的id元素(accessing id element of parent page from iframe)
- linux的常用命令干什么用的
- Feign Client + Eureka POST请求正文(Feign Client + Eureka POST request body)
- 怎么删除禁用RHEL/CentOS 7上不需要的服务
- 为什么Gradle运行测试两次?(Why does Gradle run tests twice?)
- 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
- 如何交换返回集中的行?(How to swap rows in a return set?)
- 在android中的活动之间切换?(Switching between activities in android?)
- Perforce:如何从Depot到Workspace丢失文件?(Perforce: how to get missing file from Depot to Workspace?)
- Webform页面避免运行服务器(Webform page avoiding runat server)
- 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
- 内存布局破解(memory layout hack)
- 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
- 我们可以有一个调度程序,你可以异步添加东西,但会同步按顺序执行吗?(Can we have a dispatcher that you can add things todo asynchronously but will be executed in that order synchronously?)
- “FROM a,b”和“FROM a FULL OUTER JOIN b”之间有什么区别?(What is the difference between “FROM a, b” and “FROM a FULL OUTER JOIN b”?)
- Java中的不可变类(Immutable class in Java)
- bat批处理文件结果导出到txt
- WordPress发布查询(WordPress post query)
- 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
- 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
- 德州新起点计算机培训学校主要课程有什么?
- GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
- “latin1_german1_ci”整理来自哪里?(Where is “latin1_german1_ci” collation coming from?)