按升序 ID 将数据存储在表中 [英] store data in table by ascending IDs

查看:79
本文介绍了按升序 ID 将数据存储在表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,我必须从excel文件中读取数据并将它们存储在数据库中.我使用 LinkedHashmap 将每个单元格作为字符串读取并存储.我的 excel 文件包含数据:

i have a program where i have to read data from excel file and store them in a database . I am using LinkedHashmap to read each cell as a string and store them. My excel file contains the data:

ID    Name        Salary
43    paulina     1000
5     christine   2349000
54    laura       12587458
49    jim         45878

在我的代码中,我在 Excel 文件的第一行创建了表格的字段,然后我再次使用 LinkedHashMap 用其余数据填充了表格.我的问题是在这一步中我如何将数据存储在表中,而不是它们在文件中的方式,而是通过升序 ID.我搜索我可以用 TreeMap 做到这一点,但究竟如何?有人可以帮我吗?

In my code I have made the fields for the table by the first row of the excel file and then I have filled the table with the rest of the data using again LinkedHashMap. My question is how in this step I can store the data in the table not the way they are in the file but by ascending IDs. I search that i can do it with TreeMap but how exactly? Could anyone help me?

推荐答案

DBMS(如 MySQL、Oracle 等)的一个特点是每一行数据都是独立的.行在 DBMS 中的存储没有自然顺序.

A characteristic of DBMSs (like MySQL, Oracle, etc) is that each row of data stands alone. There is no natural order in which rows are stored in a DBMS.

也就是说,当您使用 SELECT 语句检索行时,它们在结果集中呈现给您的顺序在形式上是不可预测的.如果您希望以可预测的顺序显示行,请在 SELECT 语句中使用 ORDER BY 子句.

That is, when you retrieve the rows using a SELECT statement, the order in which they will be presented to you in your result set is formally unpredictable. If you want your rows presented in a predictable order, use an ORDER BY clause in your SELECT statement.

碰巧某些 DBMS 技术会产生行以特定顺序存储的错觉.但他们对此不作任何承诺,除非您使用 ORDER BY,否则这种错觉随时可能破灭.当表达到特定大小时应用程序开始出现故障时,我艰难地了解到这一点.

It happens that some DBMS technology presents the illusion that rows are stored in a particular order. But they make no promises about this, and the illusion can break at any time unless you use ORDER BY. I learned this the hard way when an application started malfunctioning when a table got to a certain size.

INSERT 将它们导入 MySQL 之前对它们进行排序,因此,是在浪费您的时间.让您的插入软件非常简单.当你把它们拿出来时订购它们非常简单——使用 ORDER BY.

To order your rows before INSERTing them into MySQL is, therefore, a waste of your time. Keep your insertion software really simple. To order them when you get them out is trivially easy -- use ORDER BY.

这篇关于按升序 ID 将数据存储在表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆