Which is faster: manual processing of a single query in Java or doing multiple selects in SQL Server? -


Which should be faster?

1) Selecting on a SQL server three times and then adding the result to array lists on Java,

SQL Server

  Count from the table (1) Select where somecriteria = "true"; - stmt1 selection count (1) From the table where somecriteria = "false"; - Select count from STMT2 table (1); - stmt3, values ​​are either true or false  

Java

  ResultSet rs1 = stmt1.executeQuery (); Whereas (rs1.next ()) {arrayList1.add (someKeyGeneratingMethod1 ()); } Results set rs2 = stmt2.executeQuery (); While (rs2.next ()) {arrayList2.add (someKeyGeneratingMethod2 ()); } Results set rs3 = stmt3.executeQuery (); While (rs3.next ()) {arrayList3.add (someKeyGeneratingMethod3 ()); }  

Or, 2) Is it time to choose to use SQL Server and then processing results in array lists on Java?

SQL Server

  Select the number from the table (1); - STMT, values ​​are either true or false  

Java

  ResultSet rs = stmt.executeQuery (); While (rsnext ()) {string x = rs.getString (1); If ("true" .equals (x)) {arrayList1.add (someKeyGeneratingMethod1 ()); } And {arrayList2.add (someKeyGeneratingMethod2 ()); } ArrayList3.add (some KeyGeneratingMethod3 ()); }  

Since it's just counting 3, using Java to execute 3 statements There is no need for that. This will slow down the process from receiving a query and opposing processing inside Java. The reason for this is that using SQL to execute a SQL statement, it is a workflow of yourself and you will start this workflow three times.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -