0

I'm adding a downloaded jar to my lib folder, but when I try to use it doesn't work.

Here is the code:

// make sure the ClassLoader has the MonetDB JDBC driver loaded
Class cls = Class.forName("nl.cwi.monetdb.jdbc.MonetDriver");
// request a Connection to a MonetDB server running on 'localhost'
Connection con = DriverManager.getConnection("jdbc:monetdb://localhost/testDB", "monetdb", "monetdb");
Statement st = con.createStatement();

There is no code problems because I created a java app with same code and it works, the problem is grails is not taking the jar into the class path. So finaly here is my buildConfig.groovy

grails.project.dependency.resolver = "maven" // or ivy
grails.project.dependency.resolution = {
    // inherit Grails' default dependencies
    inherits("global") {
        // uncomment to disable ehcache
        // excludes 'ehcache'
    }
    log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
    repositories {
        grailsCentral()
        mavenLocal()
        mavenCentral()
        // uncomment the below to enable remote dependency resolution
        // from public Maven repositories
        //mavenRepo "http://repository.codehaus.org"
        //mavenRepo "http://download.java.net/maven/2/"
        //mavenRepo "http://repository.jboss.com/maven2/"


    }
    dependencies {
        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
        // runtime 'mysql:mysql-connector-java:5.1.27'

    }

    plugins {
        build ":tomcat:8.0.22"
        build(":release:3.0.1",
              ":rest-client-builder:1.0.3") {
            export = false
        }
    }
Federico
  • 58
  • 2
  • 12
  • Are you trying to use this as a db for your grails application? – Neoryder Oct 09 '15 at 01:18
  • I'm creating a plugin to make monetDB connection easier in any grails-app. Like the mysql or mongo plugins – Federico Oct 09 '15 at 01:41
  • Take a look at how graeme does it here: https://github.com/grails/grails-data-mapping – Neoryder Oct 09 '15 at 01:47
  • Sorry @Neoryder but I don't see how that can help me. What i'm trying to do is implementing a custom connection from a custom jar. Implementing a new gorm for monetDB (there is no one for grails yet) will take me more time and now I can't afford it (in the future I'll certainly do it but not this year) – Federico Oct 09 '15 at 02:05

1 Answers1

3

Take a look at this document: http://grails.github.io/grails-doc/latest/guide/conf.html#dataSource

Define the monetdb as a dependency using BuildConfig.groovy by adding this 'monetdb:monetdb-jdbc:2.8'

Then update the entries in the Datasource.groovy file.

Now from your controller yuo have to inject the datasource.

SampleController{

def dataSource

  def index(){
      def sql = new Sql(dataSource)
      sql.executeUpdate('select * from testdb.something')
  }

}
Neoryder
  • 897
  • 2
  • 13
  • 26
  • What's confusing me is next line in the link you provide: "If you can't use dependency resolution then just put the JAR in your project's lib directory." – Federico Oct 09 '15 at 01:45
  • The preferred way of dealing with dependency is by using dependency resolution. For a long time Oracle JDBC Drivers did not have a maven repository. This meant that to use it you had to put it in the lib folder. – Neoryder Oct 09 '15 at 01:48
  • I'm actually adding the jar to the lib folder, also added the 'monetdb:monetdb-jdbc:2.17' line to dependencies and The error I get is : Message No suitable driver found for jdbc:monetdb://localhost/testDB Around line 11 of grails-app/controllers/monetdbconnector/OdbcController.groovy 8: // make sure the ClassLoader has the MonetDB JDBC driver loaded9: Class cls = Class.forName("nl.cwi.monetdb.jdbc.MonetDriver");10: The error occurs with 'monetdb:monetdb-jdbc:2.17' in dependencies and without it. – Federico Oct 09 '15 at 01:55
  • But you dont call the MonetDriver like that. – Neoryder Oct 09 '15 at 02:00