mybatis无法使用oracle数据库生成

时间:2015-09-27 08:59:12

标签: oracle11g generator mybatis ibatis

我得到了generatorConfig.xml这样的话:

<generatorConfiguration>
    <classPathEntry location="D:\Workspace\springlt\src\main\resources\ojdbc6.jar" />

    <context id="MyBatis3" targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressAllComments" value="true" />
        </commentGenerator>

        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
            connectionURL="myurl" userId="username"
            password="password">
        </jdbcConnection>

        <javaModelGenerator targetPackage="vn.laptrinh.domain"
            targetProject="../java" />

        <sqlMapGenerator targetPackage="vn.laptrinh.dao.xml"
            targetProject="../java" />

        <javaClientGenerator type="XMLMAPPER"
            targetPackage="vn.laptrinh.dao" targetProject="../java" />

        <!-- <table tableName="users" domainObjectName="User"
            enableSelectByExample="false" enableDeleteByExample="false"
            enableCountByExample="false" enableUpdateByExample="false">
            <columnOverride column="id" javaType="Long" />
        </table> -->

        <table tableName="CARDUSER_MASTER" domainObjectName="CardUserMaster"
            schema="CACISISS" enableSelectByExample="false"
            enableDeleteByExample="false" enableCountByExample="false"
            enableUpdateByExample="false">
        </table>
    </context>
</generatorConfiguration>

以前,我使用mysql数据库并将mysql-connector-java-5.1.15-bin.jarmybatis-generator-core-1.3.1.jar放在.. \ springlt \ src \ main \ resources文件夹中,然后使用命令行到run java -jar mybatis-generator-core-1.3.1.jar -configfile generatorConfig.xml -overwrite -tables users,项目将生成domain, xml, xmlmapper

然而,当我将mysql-connector-java-5.1.15-bin.jar更改为ojdbc6.jar(我正在使用oracle 11g)时,我会遇到一堆错误:

D:\Workspace\springlt\src\main\resources>java -jar mybatis-generator-core-1.3.1.
jar -configfile generatorConfig.xml
Exception in thread "main" java.lang.RuntimeException: Exception getting JDBC Dr
iver
        at org.mybatis.generator.internal.db.ConnectionFactory.getDriver(Connect
ionFactory.java:85)
        at org.mybatis.generator.internal.db.ConnectionFactory.getConnection(Con
nectionFactory.java:54)
        at org.mybatis.generator.config.Context.getConnection(Context.java:498)
        at org.mybatis.generator.config.Context.introspectTables(Context.java:40
8)
        at org.mybatis.generator.api.MyBatisGenerator.generate(MyBatisGenerator.
java:221)
        at org.mybatis.generator.api.ShellRunner.main(ShellRunner.java:117)
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at org.mybatis.generator.internal.ObjectFactory.externalClassForName(Obj
ectFactory.java:90)
        at org.mybatis.generator.internal.db.ConnectionFactory.getDriver(Connect
ionFactory.java:82)
        ... 5 more

我不知道问题是什么。我连接到位于服务器上的数据库。

任何解决方案都将不胜感激。感谢。

2 个答案:

答案 0 :(得分:1)

首先,请更改此内容:

<jdbcConnection driverClass="com.mysql.jdbc.Driver"
        connectionURL="myurl" userId="username"
        password="password">
    </jdbcConnection>

<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"
        connectionURL="myurl" userId="username"
        password="password">
    </jdbcConnection>

并查看它是否适合您

答案 1 :(得分:0)

我已经正确配置了所有内容,并意识到导致此错误的原因还可能是该插件无法找到ojdbc jar。对我有用的是在生成器文件中添加classPathEntry。

 <generatorConfiguration>    
  <classPathEntry location="/Users/adaprognotebook/lib/ojdbc6.jar"/>     
  <context id="system" >
    <plugin type="org.mybatis.generator.plugins.CaseInsensitiveLikePlugin" />
...