title: Execute While in SQl Script in Java
body: <p>i want to execute the SQL Script below, therefore i used ibatis Script Runner</p>
  
  <pre><code>Connection "con = DriverManager.getConnection("jdbc:odbc:Database")" 
  
  ScriptRunner sr = new ScriptRunner(con, true, false);
  // Give the input file to Reader
  Reader reader = new BufferedReader(new FileReader(aSQLScriptFilePath));
  // Execute script
  sr.runScript(reader);
  </code></pre>
  
  <p>But there is the Problem, that While loops will not  be completely executed.
  I pointed out that the problem comes because the Script Runner didn´t wait until he while loop is completely done. So there are only 386 and not 1000 rows created.
  I got the same Problem using the Java Statement execute method(<a href="http://docs.oracle.com/javase/6/docs/api/java/sql/Statement.html" rel="nofollow">http://docs.oracle.com/javase/6/docs/api/java/sql/Statement.html</a>):</p>
  
  <pre><code> stmnt.execute("DECLARE @variable int = 1 WHILE (@variable&lt;=1000) BEGIN INSERT INTO BatchTest2 SELECT @variable SET @variable=@variable+1 END" );
  </code></pre>
  
  <p>But if i set </p>
  
  <pre><code>Thread.sleep(5000);
  </code></pre>
  
  <p>behind stmnt.execute the while loop is completeley done and i get 1000 rows like i wanted.
  So my question is, if it is possible to execute the complete While loop whitout using Thread.sleep.?</p>
  
  <p>Thank you in advance! </p>
  
  <pre><code>IF OBJECT_ID('test') IS NOT NULL
  DROP TABLE test;
  
  CREATE TABLE test(
  spalte1 int PRIMARY KEY NOT NULL);
  
  DECLARE @variable int = 1
  WHILE (@variable&lt;=1000)
  BEGIN
  INSERT INTO test
  SELECT @variable
  SET @variable=@variable+1
  END 
  </code></pre>