Menu

ucanaccess using maven problem

Help
2015-11-20
2015-11-20
  • Peter Stevenson

    Peter Stevenson - 2015-11-20

    Hi,
    I’m trying to use the @Grab annotation in a Groovy script to get ucanaccess from Maven repository.
    I get this error:-

    Caught: java.sql.SQLException: No suitable driver found for jdbc:ucanaccess://C:/temp/Observatory_Database.mdb
    java.sql.SQLException: No suitable driver found for jdbc:ucanaccess://C:/temp/Observatory_Database.mdb
    at create_observatories_xml.run(create_observatories_xml.groovy:32)

    The script works fine with manually downloaded jars in the classpath but it would be nice to use Grape to handle dependencies.
    Any thoughts why this doesn’t work?

    My script is like this:-

    import java.io.FileWriter;
    import groovy.sql.Sql
    import groovy.xml.MarkupBuilder
    import groovy.swing.SwingBuilder
    import javax.swing.JFileChooser
    import javax.swing.UIManager

    @Grab(group='net.sf.ucanaccess', module='ucanaccess', version='3.0.2')

    database = this.args ? this.args[0] : null

    if (!database) {
    try { UIManager.lookAndFeel = UIManager.systemLookAndFeelClassName } catch (Exception e) { }
    def fileChooser = new SwingBuilder().fileChooser()
    fileChooser.currentDirectory = new File('.')
    fileChooser.fileFilter = [ accept : { file -> file.isDirectory() || file =~ /.mdb$/ }, getDescription : { "Microsoft Access Database (*.mdb)" } ] as javax.swing.filechooser.FileFilter
    fileChooser.acceptAllFileFilterUsed = false
    fileChooser.dialogTitle = "Choose an Observatory Contacts database"
    if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) database = fileChooser.getSelectedFile().toString()
    else return 1
    }

    outputDirectory = "."

    //connect to AccessDB with ucanaccess client
    database = database.replaceAll('\\','/')
    def connectionString = "jdbc:ucanaccess://${database}"
    def sql = Sql.newInstance(connectionString, "", "", "net.ucanaccess.jdbc.UcanaccessDriver")

    def outputFile = new File(outputDirectory, "observatories.xml")
    def outputWriter = new FileWriter(outputFile)
    def builder = new MarkupBuilder(outputWriter)

    builder.observatories() {
    sql.eachRow("SELECT iaga_id, name FROM obsdetgen_observatory_details") { obs ->
    observatory( iaga_code: obs.iaga_id, obs.name)
    }
    }

    Thanks,
    Peter.

     
    • Gord Thompson

      Gord Thompson - 2015-11-20

      Have a look at

      http://stackoverflow.com/q/20009993/2144390

      It suggests that adding

      @GrabConfig(systemClassLoader= true)
      

       
      might help. (Some of the comments to the answer could prove helpful as well.)

       
  • Peter Stevenson

    Peter Stevenson - 2015-11-20

    Thanks Gord - adding @GrabConfig(systemClassLoader= true) works.
    This wasn't necessary for other @Grab annotations so that was confusing.
    Anyway not a ucanaccess issue so I appreciate the help.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.