操作方法:Grails 3.0.2 + Oracle Database 12c? [英] How-to: Grails 3.0.2 + Oracle Database 12c?

查看:109
本文介绍了操作方法:Grails 3.0.2 + Oracle Database 12c?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开始使用Grails的第一步,并尝试使用Oracle Database 12c创建一个hello world应用程序。



不幸的是,关于数据库特定部分的教程文档www.grails.org似乎并不全面(与我现在使用的Ruby on Rails相比,这一点已经好几年了) - 特别是涉及到非H2数据库时。



是否有最近的教程介绍如何使用Oracle Database 12c启动并运行Grails 3.0.2?



主要关注a)在哪里放置相应的JDBC驱动程序,以及b)数据库配置应该如何。



对于a)

grails.org谈论一个lib目录,但没有解释它存在或应该创建的位置。其他消息来源说,lib目录已经过时了,因为有几个Grails版本,并且应该通过某些存储库的依赖来加载JDBC驱动程序 - 这对于闭源Oracle JDBC驱动程序显然是不可能的。



对于b)



目前,我已经在< my-app> / grails-

  dataSource {
url = jdbc:oracle:thin:@ my-server:my-port:my-sid
driverClassName =oracle.jdbc.OracleDriver
dialect =Oracle10gDialect
username =my -user
password =my-pass
}

对于一个简单的Hello World应用程序来说足够了吗?

到目前为止,我在网上发现的所有东西都是过时的,不管是在Grails方面(包括2.x或1.x版本)和/或Oracle方面(涵盖版本10 *或11 *)。



谢谢f或任何提示!






更新(仅用于记录并将以下评论):

<1>


编辑< myapp> / grails-app / conf / application.yml

  hibernate:
jdbc:
use_get_generated_keys :true
(...)
dataSource:
pooled:true
jmxExport:true
driverClassName:oracle.jdbc.OracleDriver
username:<为myuser>
密码:< mypassword>
(...)
环境:
开发:
dataSource:
dbCreate:create
url:jdbc:oracle:thin:@< myserver> ;:其中MyPort上>:其中糠>
(...)



<2>



获取适合您的JDK和Oracle DB版本的相应Oracle JDBC驱动程序。在我的情况下(openJDK 7 + Oracle 12c),这是来自Oracle网站的ojdbc7.jar版本12.1.0.2.0: http://www.oracle.com/technetwork/database/features/jdbc/index.html



3 )



将此JDBC驱动程序放在< myapp> / lib 中(如果尚未创建此目录)



将此JDBC驱动程序的详细信息添加到<$ c $的依赖项部分c>< myapp> /build.gradle (根据需要进行修改以适应您的环境/版本):

 <$ c (...)
依赖关系
(...)
运行时com.oracle.ojdbc7:12.1.0.2.0
(...)

(...)

5)



创建一个Maven工件(如果需要,修改以适应您的环境/版本):

  mvn install:install-file -Dfile = lib / ojdbc7.jar -DgroupId = com.oracle -Dartifac tId = ojdbc7 -Dversion = 12.1.0.2.0 -Dpackaging = jar -DgeneratePom = true 

6)

将JDBC驱动程序的路径添加到您的CLASSPATH: export CLASSPATH = /< somewhere> /< myapp> / lib / ojdbc7。 jar



7)



享受...

解决方案

是的,这段时间可以。但是缺少细节。
我一到我的办公室就会发布详细说明。
实际上,在grails站点的某个地方有一个用于mySql的示例,从中可以清楚地知道如何为oracle数据库创建相同的示例。



我只是有创建了一个新的应用程序,并将其与myne for oracle 11g进行了比较。
这里是:


  1. ./ build.gradle,在dependencies部分添加以下行: p>

    运行时com.oracle:ojdbc14:10.2.0.3.0


  2. ./ grails-app /conf/application.yml,将以下内容添加到hibernate部分:




  3. <$ p $

















    $




  dataSource:
pooled:true
jmxExport:true
driverClassName:oracle.jdbc。 OracleDriver
用户名:YOURUSERNAME
密码:yoursecret




< ol start =4>

  • ./ grails-app / conf / application.yml,environments:configuration,所有这三种环境都应该是这样的:




     环境:
    deve lopment:
    dataSource:
    dbCreate:create
    url:jdbc:oracle:thin:@ somehost.net:1521:YOURORAINSTANCE
    测试:
    dataSource:
    dbCreate:update
    url:jdbc:oracle:thin:@ somehost.net:1521:YOURORAINSTANCE
    产品:
    dataSource:
    dbCreate:更新
    url:jdbc :oracle:thin:@ somehost.net:1521:YOURORAINSTANCE


    而且你用的Oracle的Hibernate方言是非常古老的,我认为你最好删除它,而不是明确地指定它,所有工作都很好。


    I am making my first steps with Grails and try to create a hello world application with an Oracle Database 12c.

    Unfortunately the tutorial documentation on the database specific part at www.grails.org seems not that comprehensive (in contrast for example to that of Ruby on Rails, which I used now several years) - especially when it comes to non-H2 databases.

    Is there some recent tutorial on how to get a Grails 3.0.2 app up and running with an Oracle Database 12c?

    Mainly I am interested on a) where to put the corresponding JDBC driver and b) how the database configuration should look like.

    For a)

    grails.org talks about a "lib" directory but does not explain, where it exists or should be created. Other sources say, that the "lib" directory is outdated since several Grails versions and that JDBC drivers should be loaded via dependencies from some repositories - which is obviously not possible with the closed-source Oracle JDBC driver.

    For b)

    Currently, I have created basic database configuration at <my-app>/grails-app/conf/DataSource.groovy for Oracle 12c:

    dataSource {
            url = "jdbc:oracle:thin:@my-server:my-port:my-sid"
            driverClassName = "oracle.jdbc.OracleDriver"
            dialect = "Oracle10gDialect"
            username = "my-user"
            password = "my-pass"
    }
    

    Should that be enough for a simple hello world app?

    Everything I have found so far at the web is outdated either on the Grails side (covering versions 2.x oder 1.x) and/or the Oracle side (covering versions 10* oder 11*).

    Thanks for any hints!


    Update (just for the record and to bring together the comments below):

    1)

    Edit <myapp>/grails-app/conf/application.yml.

    hibernate:
        jdbc:
            use_get_generated_keys: true
    (...)
    dataSource:
        pooled: true
        jmxExport: true
        driverClassName: oracle.jdbc.OracleDriver
        username: <myuser>
        password: <mypassword>
    (...)
    environments:
        development:
            dataSource:
                dbCreate: create
                url: jdbc:oracle:thin:@<myserver>:<myport>:<mysid>
    (...)
    

    2)

    Get the corresponding Oracle JDBC driver that fits your JDK and Oracle DB release. In my case (openJDK 7 + Oracle 12c) this was ojdbc7.jar release 12.1.0.2.0 from the Oracle Website: http://www.oracle.com/technetwork/database/features/jdbc/index.html

    3)

    Place this JDBC driver in <myapp>/lib (create this directory, if it does not yet exists).

    4)

    Add details of this JDBC driver to the dependencies section of <myapp>/build.gradle (modify if necessary to fit your environment/releases):

    (...)
    dependencies {
        (...)
        runtime "com.oracle.ojdbc7:12.1.0.2.0" 
        (...)
    }
    (...)
    

    5)

    Create a Maven artifact (modify if necessary to fit your environment/releases):

    mvn install:install-file -Dfile=lib/ojdbc7.jar -DgroupId=com.oracle -DartifactId=ojdbc7 -Dversion=12.1.0.2.0 -Dpackaging=jar -DgeneratePom=true
    

    6)

    Add the path to the JDBC driver to your CLASSPATH: export CLASSPATH=/<somewhere>/<myapp>/lib/ojdbc7.jar

    7)

    Enjoy ...

    解决方案

    yes this will be OK for meanwhile. But there are details missing. I'll post detailed instructions as soon as i get to the office. Actually there is a sample for mySql somewhere on the grails site, and from it it's pretty clear how to make same for an oracle DB.

    I just have created a new app and compared it with myne for oracle 11g. Here it is:

    1. ./build.gradle, add following line to "dependencies" section:

      runtime "com.oracle:ojdbc14:10.2.0.3.0"

    2. ./grails-app/conf/application.yml, add following to "hibernate" section:

    jdbc:
        use_get_generated_keys: true
    

    1. ./grails-app/conf/application.yml, dataSource: section should be like:

    dataSource:
        pooled: true
        jmxExport: true
        driverClassName: oracle.jdbc.OracleDriver
        username: YOURUSERNAME
        password: yoursecret
    

    1. ./grails-app/conf/application.yml, environments: configuration, all three environments should be like:

    environments:
    development:
        dataSource:
            dbCreate: create
            url: jdbc:oracle:thin:@somehost.net:1521:YOURORAINSTANCE
    test:
        dataSource:
            dbCreate: update
            url: jdbc:oracle:thin:@somehost.net:1521:YOURORAINSTANCE
    production:
        dataSource:
            dbCreate: update
            url: jdbc:oracle:thin:@somehost.net:1521:YOURORAINSTANCE
    

    And the Hibernate dialect for Oracle you have is pretty old one, I think you'd better remove it, without specifying it explicitly all works fine.

    这篇关于操作方法:Grails 3.0.2 + Oracle Database 12c?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆