Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-3417

groovy.sql.Sql throws ClassNotFoundException when called via GroovyShell that explicitly adds jdbc jar to classpath

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.6
    • None
    • SQL processing
    • None
    • macos 10.5, java 1.6

    Description

      The following script fails with a ClassNotFoundException. The script has no problem instantiating the com.mysql.jdbc.Driver class, but groovy.sql.Sql can't do the same. This may be related to GROOVY-3413.

      import java.net.URL
      import java.net.URLClassLoader
      
      def cp = []
      cp << new URL("file:mysql-connector-java-5.1.6-bin.jar")
      def loader = new URLClassLoader(cp as URL[], this.class.classLoader)
      
      def shell = new GroovyShell(loader)
      
      def script = """
          assert null != new com.mysql.jdbc.Driver()
      """
      shell.evaluate(script)
      
      script = """
          import groovy.sql.Sql
          assert null != Sql.newInstance("jdbc:mysql://localhost:3306/db", "user", "pass", "com.mysql.jdbc.Driver")
      """
      shell.evaluate(script)
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            andyfyfe Andy Fyfe
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: