解决运行mybatis-generator生成java.sql.SQLException: Cannot connect to database (possibly bad driver/URL co
2020-03-05 00:36
232 查看
一、异常描述
在eclipse中通过mybatis-generator生成dao、mappers及model代码时(步骤参考“通过mybatis-generator-core工具自…”页面),报“java.sql.SQLException: Cannot connect to database (possibly bad driver/URL combination)”异常,错误轨迹如下
java.sql.SQLException: Cannot connect to database (possibly bad driver/URL combination) at org.mybatis.generator.internal.db.ConnectionFactory.getConnection(ConnectionFactory.java:71) at org.mybatis.generator.config.Context.getConnection(Context.java:498) at org.mybatis.generator.config.Context.introspectTables(Context.java:408) at org.mybatis.generator.api.MyBatisGenerator.generate(MyBatisGenerator.java:221) at org.mybatis.generator.api.MyBatisGenerator.generate(MyBatisGenerator.java:132) at com.xwood.gen.GeneratorExecuter.generator(GeneratorExecuter.java:24) at com.xwood.gen.GeneratorExecuter.main(GeneratorExecuter.java:29)
二、解决办法
1.从异常描述信息直接可以看出是generator.xml的jdbcConnection配置文件配错了
2.关于jdbcConnection配置,mysql的配置应该如下,"connectionURL=“jdbc:mysql://192.168.1.9:3306/test”
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://192.168.1.9:3306/test" userId="root" password="123456"> </jdbcConnection>
3.详细generator.xml参考如下
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> <generatorConfiguration> <!-- classPathEntry:数据库的JDBC驱动--> <classPathEntry location="C:\WS\mybatis-generator-core-1.3.1\lib\mysql-connector-java-3.2.0-alpha-bin.jar" /> <context id="DB2Tables" targetRuntime="MyBatis3"> <!-- 去除自动生成的注释 --> <commentGenerator><property name="suppressAllComments" value="true" /></commentGenerator> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://192.168.1.9:3306/test" userId="root" password="123456"> </jdbcConnection> <javaTypeResolver > <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- targetProject:自动生成model代码的位置 --> <javaModelGenerator targetPackage="com.xwood.gen.model" targetProject="C:\WS\NJ\project\xwood-project\JavaTest\src\"> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <!-- targetProject:自动生成mappers代码的位置 --> <sqlMapGenerator targetPackage="com.xwood.gen.mappers" targetProject="C:\WS\NJ\project\xwood-project\JavaTest\src\"> <property name="enableSubPackages" value="true" /> </sqlMapGenerator> <!-- targetProject:自动生成dao代码的位置 --> <javaClientGenerator type="XMLMAPPER" targetPackage="com.xwood.gen.dao" targetProject="C:\WS\NJ\project\xwood-project\JavaTest\src\"> <property name="enableSubPackages" value="true" /> </javaClientGenerator> <!-- tableName:用于自动生成代码的数据库表;domainObjectName:对应于数据库表的javaBean类名--> <table tableName="guser" domainObjectName="Guser" > </table> </context> </generatorConfiguration>
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- 运行mybatis-generator生成 Cannot connect to database (possibly bad driver/URL combination)异常mysql8
- Cannot connect to database (possibly bad driver/URL combination)问题解决
- java.sql.SQLException: null, message from server: “Host ‘xxx’ is not allowed to connect异常解决
- 异常:Caused by: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'--解决方法
- SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null' 解决办法
- SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null' 解决办法
- java.sql.SQLException: The value supplied cannot be converted to DECIMAL 解决方法
- SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null' 解决办法
- 解决java.sql.SQLException: null, message from server: "Host 'XXX' is not allowed to connect异常
- Hive 笔记异常(java.sql.SQLException: Unable to open a test connection to the given database. JDBC url =)
- mybatis 执行查询时报错 【Error querying database. Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: 】
- java.sql.SQLException: The value supplied cannot be converted to DECIMAL 解决方法
- JBoss启动时报Problem starting service jboss:service=Hypersonic,database=localDB,java.sql.SQLException: User not found: SA解决办法
- 远程mysql_java.sql.SQLException: null, message from server: "Host 'xxx' is not allowed to connect
- java.sql.SQLException: null, message from server: "Host 'xxx' is not allowed to connect to this MySQL server"
- 出现java.sql.SQLException: No suitable driver的几种解决办法
- Tomcat 部署 时 java.sql.SQLException: No suitable driver found for jdbc:sqlserver 我是怎么解决的
- 关于 java.sql.SQLException: Bad format for Date错误的解决方法
- java.sql.SQLException: null, message from server: "Host 'xxx' is not allowed to connect
- java.lang.ClassCastException: com.sun.proxy.$Proxy0 cannot be cast to java.sql.Connection异常问题解决