Found solution,
<mule ...
<flow name="createFlow1" doc:name="createFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
<scripting:component doc:name="Python">
<scripting:script engine="jython" >from java.lang import Class
from java.sql import Statement, ResultSet, DriverManager
def importJar(jarFile):
from java.net import URL, URLClassLoader
from java.lang import ClassLoader
from java.io import File
m = URLClassLoader.getDeclaredMethod("addURL", [URL])
m.accessible = 1
m.invoke(ClassLoader.getSystemClassLoader(), [File(jarFile).toURL()])
importJar("C:/software/jar/hsqldb.jar")
importJar("C:/software/jar/sqljdbc4.jar")
Class.forName("org.hsqldb.jdbc.JDBCDriver");
connection = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/testdb","sa","")
statement = connection.createStatement()
resultSet = statement.executeQuery("select * from Persons");
while resultSet.next():
print "%s (%s)" % (resultSet.getString("firstname"), resultSet.getString("city"))
</scripting:script>
</scripting:component>
</flow>
</mule>
Solution for Groovy:
@Grapes([
@Grab('org.slf4j:slf4j-simple:1.5.11'),
@Grab('mysql:mysql-connector-java:5.1.12'),
@GrabConfig(systemClassLoader = true)
])
import groovy.sql.*
...
// Note, change jar accordingly.
By default the dependencies are available in the same classloader as our Jython/Groovy script or application. But sometimes this is not enough. For example if we have a script with a dependency on a SQL database driver and in our code java.sql.DriverManager.getConnection() is used we want our driver class to be on the system classloader. That is because the DriverManager class only can 'see' classes in the system classloader and not other classloaders. A possible exception we get is java.sql.SQLException: No suitable driver found.
You can have see below discussion for more details: