Search code examples
oracle-databasegrails

Connect Oracle database to Grails 3


I am trying to use an Oracle database to a Grails project. I work with the command line tool.

So far:

  • I have put the ojdb6 into a lib directory I had to create myself, at the root of my application

  • I modified application.yml as follow:

    dataSource:
        pooled: true
        jmxExport: true
        driverClassName: oracle.jdbc.OracleDriver
        username: usrname
        password: pwd
    
    environments:
        development:
            dataSource:
                dbCreate: create-drop
                url: jdbc:oracle:thin:@//url:port/db
        test:
            dataSource:
                dbCreate: update
                url: jdbc:oracle:thin:@//url:port/db
        production:
            dataSource:
                dbCreate: update
                url: jdbc:oracle:thin:@//url:port/db
                properties:
                    jmxEnabled: true
                    initialSize: 5
                    maxActive: 50
                    minIdle: 5
                    maxIdle: 25
                    maxWait: 10000
                    maxAge: 600000
                    timeBetweenEvictionRunsMillis: 5000
                    minEvictableIdleTimeMillis: 60000
                    validationQuery: SELECT 1
                    validationQueryTimeout: 3
                    validationInterval: 15000
                    testOnBorrow: true
                    testWhileIdle: true
                    testOnReturn: false
                    jdbcInterceptors: ConnectionState
                    defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED
    
  • I also created a domain-class with an Integer attribute, just to give it a try.

However, it doesn't seem to work. I get a huge error message that doesn't even fit in my command window. When I use --stacktrace, the first message is "Failed to start server".

I've been trying to solve this problem for three days, any idea/comment will be welcome. Thank you kindly.

Side note: everythink works perfectly when I use the default database, not changing anything in the configuration.


Solution

  • Try below, it should work. if it doesn't post the stack trace. below snippet worked for me.

    Add dependency: runtime 'oracle:ojdbc6:11.2.0.4.0'

    Changes in application.yml:

    environments:
        dataSource:
            pooled: true
            jmxExport: true
            driverClassName: org.h2.Driver
            username: sa
            password:
    
    
    development:
        dataSource:
            dbCreate: validate
            url: jdbc:oracle:thin:@xxxx:1521:xx
            driverClassName: oracle.jdbc.OracleDriver
            dialect: org.hibernate.dialect.Oracle10gDialect
            username: "XXXXXX"
            password: "XXXXXX"
            properties:
               ***: **
               ***: **
    test:
        dataSource:
            dbCreate: update
            url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
    
    production:
        dataSource:
            dbCreate: update
            url: jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
            properties:
                jmxEnabled: true
                initialSize: 5
                maxActive: 50
                minIdle: 5
                maxIdle: 25
                maxWait: 10000
                maxAge: 600000
                timeBetweenEvictionRunsMillis: 5000
                minEvictableIdleTimeMillis: 60000
                validationQuery: SELECT 1
                validationQueryTimeout: 3
                validationInterval: 15000
                testOnBorrow: true
                testWhileIdle: true
                testOnReturn: false
                jdbcInterceptors: ConnectionState
                defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED