title: Access multiple databases in Mule ESB
body: <p>I have a Mule flow that needs to connect to a user-specified database, as opposed to a static datasource configured into the flow. </p>
  
  <p>I've got the connection parameters - URL, user, etc - and I'm trying to write a simple block of Groovy script to establish a connection to the target database using code like this:</p>
  
  <pre><code>sql = Sql.newInstance(“jdbc:mysql://localhost:3306/DB", “root”, “pass”, “com.mysql.jdbc.Driver");  
  </code></pre>
  
  <p>I've tried several variations of Sql.newInstance, but no matter what I've tried, I'm getting
  <strong><code>javax.script.ScriptException: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306</code></strong>. </p>
  
  <p>The MySQL driver (mysql-connector-java-5.1.26-bin.jar) is included in my Mule project (I see it as a “Referenced Library”). I've tried placing the Jar file in several places as recommended by other posters, but no change. </p>
  
  <p>I don't believe this is a missing Jar file issue. If I declare a static datasource in my Mule project, code like this works perfectly: </p>
  
  <pre><code>JdbcConnector jdbcConnector = (JdbcConnector) muleContext.getRegistry().lookupConnector("MyDB");
  DataSource datasource = (DataSource) jdbcConnector.getDataSource();
  Connection connection = (Connection) datasource.getConnection();
  sql.setConnection(connection);
  </code></pre>
  
  <p>I have MuleStudio 3.5.0 Build 201312201424, but the behavior seems to be the same on the prior release. </p>
  
  <p>My questions: </p>
  
  <ol>
  <li>Is there some magic to getting Sql.newInstance() to work in Groovy?</li>
  <li>Is there a better way to dynamically create a JDBC connection?</li>
  </ol>