title: What is classpath for Groovy Console / jdbc driver prblem?
body: <p>Such database code is OK in Java environment (without binded value 'c'), but in Groovy console can't properly use jdbc, with exception</p>
  
  <pre><code>java.sql.SQLException: No suitable driver found for jdbc:sqlserver://localhost;databaseName=
  </code></pre>
  
  <p>Driver class is known for script (is loaded without null etc) but probably not registered in Drivermanager ?</p>
  
  <p>code (i try with and without <code>Class.forname()</code> )</p>
  
  <pre><code>import groovy.sql.Sql
  import groovy.sql.DataSet
  
  c =   Class.forName('com.microsoft.sqlserver.jdbc.SQLServerDriver')
  
  def db = [url:'jdbc:sqlserver://localhost;databaseName=... ,driver:'com.microsoft.sqlserver.jdbc.SQLServerDriver']
   def sql = Sql.newInstance(db )
  </code></pre>
  
  <p>EDIT:
  what I had checked already:</p>
  
  <ol>
  <li>fresh started Groovy console hasn't sqljdbc4.jar on classpath. </li>
  </ol>
  
  <p>Natural exception <code>java.lang.ClassNotFoundException</code> on line 4 <code>Class.forName()</code>, or if line 4 commented and parameters db with driver name the exception on line 7  <code>Sql.newInstance(db )</code></p>
  
  <p>Its logical, driver class not found etc ...</p>
  
  <p>1a. if db parameters with 3 arguments (without driver), I assume its legal (and working in other situations) exception changes to <code>SQLException: No suitable driver</code> on line 7   <code>Sql.newInstance(db )</code></p>
  
  <p>It is logical too, DriverManager don't know how to resolve key <code>jdbc:sqlserver</code> . Driver isn't registered and DriverManager have not magical knowledge what class implements.</p>
  
  <p>2.
  when I add jar to console classpath (Script / Add jar(s) to classpath) things are somewhat changed. No more <code>ClassNotFoundException</code> and variable <code>c</code> has non-null value (driver class) but <code>SQLException: No suitable driver</code> continues.</p>
  
  <p>My understanding of JDBC philosophy: (modern) JAR driver uses technique with file <code>META-INF/services/java.sql.Driver</code> to be known for <code>DriverManager</code>.
  So in correct situation 4th argument (driver class name) is not required because is discovered automatically.
  Please correct my understanding if I'm wrong.</p>
  
  <p>I have used word 'active' in this sense ("non active" means class exist and is loaded, but can be used as jdbc driver).</p>
  
  <p>My maximal code is:</p>
  
  <pre><code>import groovy.sql.Sql
  import groovy.sql.DataSet
  import java.sql.DriverManager;
  import java.util.ServiceLoader;
  
  
  c =   Class.forName('com.microsoft.sqlserver.jdbc.SQLServerDriver')
  DriverManager.getDrivers()
  ServiceLoader.load(java.sql.Driver.class)
  def db = [url:'jdbc:sqlserver://localhost;...,driver:'com.microsoft.sqlserver.jdbc.SQLServerDriver']
  def sql = Sql.newInstance(db )
  </code></pre>
  
  <p>but still <code>no suitable driver</code> Exception</p>
  
  <p>EDIT2:
  I enumerate things with such code (before newInstance() ):</p>
  
  <pre><code>StringBuilder sb = new StringBuilder();
          String grVersion = "brak";
  
          Enumeration&lt;Driver&gt; dri = DriverManager.getDrivers();
  
          for (Enumeration&lt;Driver&gt; e = dri; e.hasMoreElements();) {
              Driver e1 = e.nextElement();
              sb.append(e1.getClass().getName()).append(' ');
              sb.append(e1.getMajorVersion()).append('.').append(e1.getMinorVersion());
          }
  
  
          // get LOADED drivers niesetty
  
          ServiceLoader&lt;java.sql.Driver&gt; codecSetLoader = ServiceLoader.load(java.sql.Driver.class);
          for (Driver e1 : codecSetLoader) {
              sb.append(e1.getClass().getName()).append('!');
              sb.append(e1.getMajorVersion()).append('.').append(e1.getMinorVersion());
              sb.append("# ");
          }
  </code></pre>
  
  <p>and get</p>
  
  <pre><code>com.mysql.jdbc.Driver 5.1com.mysql.fabric.jdbc.FabricMySQLDriver 5.1com.mysql.jdbc.Driver!5.1# com.mysql.fabric.jdbc.FabricMySQLDriver!5.1# com.microsoft.sqlserver.jdbc.SQLServerDriver!4.0#  
  Exception thrown
  
  java.sql.SQLException: No suitable driver found for jdbc:sqlserver://localhost;databaseName=....
  
      at ConsoleScript11.run(ConsoleScript11:32)
  </code></pre>
  
  <p>My (basic) code executed is Tomcat environment still working ok. What's the matter?</p>