[英]How can I execute statements with in order using JDBC and Statement.executeQuery()?
I use JDBC to insert some values into a table. 我使用JDBC将一些值插入表中。 I iterate over the statemets and I wnt to execute them in the order they come: 我遍历了statemets,并按照它们出现的顺序执行它们:
for (String statement : statements) {
System.out.println(statement);
stmt.executeQuery(statement);
}
In console the statements are printed: 在控制台中,将打印以下语句:
insert into results (cod_prod,cod_prod1,scor_prod1,cod_prod2,scor_prod2,cod_prod3,scor_prod3,cod_prod4,scor_prod4) values(9100100123256,8692857013184,9.93973798303341,8710908117671,9.653580483609403,6423038000042,9.181317277303606,90005848,9.181317277303606)
insert into results (cod_prod) values(90494741)
...
And I expect they are executed in this order, but when I query the database I get the rows in different order: 而且我希望它们按此顺序执行,但是当我查询数据库时,将以不同的顺序获取行:
Why it happend in this way? 为什么会这样发生? The stmt.executeQuery(statement) open a process and it executes lower of faster depending on the statement (number of values inserted, etc)? stmt.executeQuery(statement)打开一个进程,然后根据该语句(插入的值的数量等)以较低的速度执行。 And it should be synchronized? 而且应该同步吗?
Could you give me an example of how can I execute statementsin the order the foreach give them? 您能否举一个例子,说明如何按照foreach给它们的顺序执行语句?
You are iterating and printing a Java ArrayList
or some other structure and that Java data structure has insertion - order maintained. 您正在迭代并打印Java ArrayList
或其他结构,并且该Java数据结构具有插入顺序 。
Your table is a RDBMS table and it doesn't have any such automatic ordering. 您的表是RDBMS表,没有任何此类自动排序。 In your SELECT
, you can use SQL . 在SELECT
,可以使用SQL。 ORDER BY
clause on a column to order result set rows in any order that you want. 列上的ORDER BY
子句以所需的任何顺序对结果集行进行排序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.