title: Connecting to SQLite from Java. Getting some disorder in commands
body: <p>I have a factory class which "builds" different database connectors using one and the same interface. I have no trouble with <code>MySQL</code> and <code>Postgre</code>, but I do get some troubles when I try to connect and run some queries against <code>SQLite</code> database. So, this is the disorder I see:</p>
  
  <pre><code>SQL db = SQL_Factory.build("SQLite");
  System.out.println("BEFORE CONNECT");
  db.connect();
  System.out.println("BEFORE SHOW");
  List&lt;String&gt; tables = db.show_tables();
  </code></pre>
  
  <p>and inside <code>connect()</code> method I have these debugging commands:</p>
  
  <pre><code>try{
      cnx = DriverManager.getConnection("jdbc:sqlite:" + db_path);
      System.out.println("CONNECTED");
  } 
  ....
  </code></pre>
  
  <p>As a result of running the code I expected to see this in the console:</p>
  
  <pre><code>BEFORE CONNECT
  CONNECTED
  BEFORE SHOW
  </code></pre>
  
  <p>However, what I see looks rather strange:</p>
  
  <pre><code>BEFORE CONNECT
  BEFORE SHOW
  CONNECTED
  </code></pre>
  
  <p>Indeed, I'm getting a lot of other errors, but it's quite obvious, that all of them result from this disorder - <code>CONNECTED</code> status appears long after other commands that need this connection to be set. So, I wonder where this async behaviour may come from and how to repair it? Thanks!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Well, on the official <a href="https://bitbucket.org/xerial/sqlite-jdbc" rel="nofollow">page</a> I see extremely strange lines of code:</p>
  
  <pre><code>connection = DriverManager.getConnection("jdbc:sqlite:sample.db");
  Statement statement = connection.createStatement();
  statement.setQueryTimeout(30);  // &lt;- WTF?????????
  
  statement.executeUpdate("drop table if exists person");
  </code></pre>
  
  <p>So, is it really necessary to set timeout?? It looks like rubbish.</p>