The following Groovy script works correctly from the command line. (I successfully get a Connection.)
// ---- jdbc_test.groovy import java.sql.* Class.forName("com.mysql.jdbc.Driver") def con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/test", "root", "password") println con > groovy -cp lib\mysql-connector-java-5.1.25-bin.jar script\jdbc_test.groovy [email protected]
But if the same script is loaded into GroovyConsole (2.4.3) and run - after adding the
mysql-connector-java-5.1.25-bin.jar using 'Script' | 'Add Jar(s) to ClassPath' - it fails:
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/test at java_sql_DriverManager$getConnection.call(Unknown Source) at jdbc_test.run(jdbc_test.groovy:3)
Every other package or class I have added to the classpath in GroovyConsole and experimented with has worked. Is there some unexpected interaction of Groovy's class loading and the way DriverManager works?
Is there a way around this? I'm trying to use the GroovyConsole to interactively test out some JDBC code (a library of functions, each of which takes a Connection as its first argument).
Class.forName() part appears to be working fine. If I 'Script' | 'Clear Script Context' and rerun the script in GroovyConsole, I instead get:
If I add
mysql-connector-java-5.1.25-bin.jar back in, I go back to getting:
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/test