报错
MySQL 中 使用 tk.mybatis 自动生成数据表,运行报错,发现表对象的@Table
名字多了个点
org.springframework.jdbc.BadSqlGrammarException:
Error querying database. Cause: java.sql.SQLSyntaxErrorException: You have an error in your > SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘.job’ at line 1
The error may exist in com/tonited/hello/spring/mapper/JobMapper.java (best guess)
The error may involve defaultParameterMap
The error occurred while setting parameters
SQL: SELECT id,description FROM staff_management…job
Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘.job’ at line 1; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘.job’ at line 1
手动解决
问题在于SQL语句中出现了两个点
SELECT id,description FROM staff_management..job
我们去Job这个自动生成的类中查看,发现
其实把这一部分去掉就可以正常运行,手动一个一个删掉很麻烦,也可以通过配置解决
配置解决
如果想配置生成时就去掉可以在配置文件的table
标签下添加红框部分属性
原理
SQL中下Catalog和Schema都属于抽象概念,解决命名冲突
一个数据库系统包含多个Catalog
,每个Catalog
包含多个Schema
,每个Schema
包含多个数据库对象(表、视图、字段等)
数据库对象表的全限定名可表示为:Catalog.Schema.表名
但是mysql不支持catalog
各大数据库支持情况1:
供应商 | Catalog支持 | Schema支持 |
---|---|---|
Oracle | 不支持 | Oracle User ID |
MySQL | 不支持 | 数据库名 |
MS SQL Server | 数据库名 | 对象属主名,2005版开始有变 |
DB2 | 指定数据库对象时,Catalog部分省略 | Catalog属主名 |
Sybase | 数据库名 | 数据库属主名 |
Informix | 不支持 | 不需要 |
PointBase | 不支持 | 数据库名 |
https://blog.csdn.net/ddfdjffd/article/details/90712080 ↩︎