表在数据库中不存在
我的开发环境:jeecg3.6.3, tomcat7,jdk7,mysql5.5.49jeecg搭建起来,运行,创建单表,生成代码出错,报错:表在数据库中不存在
跟踪jeecg,发现,在生成代码是,要现检验表在数据库中是存在的,检验的方法是检索information_scheam中的记录,查找指定的表是否存在,但是jeecg在构建的sql语句中,将要检索的表名称做toUpperCase()处理,结果,没有找到指定的表。
jeecg中检验表是否存在的源码如下:
public boolean checkTableExist(String tableName)
{
try
{
System.out.println((new StringBuilder()).append("\u6570\u636E\u5E93\u9A71\u52A8: ").append(CodeResourceUtil.DIVER_NAME).toString());
Class.forName(CodeResourceUtil.DIVER_NAME);
conn = DriverManager.getConnection(CodeResourceUtil.URL, CodeResourceUtil.USERNAME, CodeResourceUtil.PASSWORD);
stmt = conn.createStatement(1005, 1007);
if(CodeResourceUtil.DATABASE_TYPE.equals("mysql"))
sql = (new StringBuilder()).append("select column_name,data_type,column_comment,0,0 from information_schema.columns where table_name = '").append(tableName.toUpperCase()).append("'").append(" and table_schema = '").append(CodeResourceUtil.DATABASE_NAME).append("'").toString();
if(CodeResourceUtil.DATABASE_TYPE.equals("oracle"))
sql = (new StringBuilder()).append("select colstable.column_name column_name, colstable.data_type data_type, commentstable.comments column_comment from user_tab_cols colstableinner join user_col_comments commentstableon colstable.column_name = commentstable.column_namewhere colstable.table_name = commentstable.table_nameand colstable.table_name = '").append(tableName.toUpperCase()).append("'").toString();
if(CodeResourceUtil.DATABASE_TYPE.equals("postgresql"))
sql = MessageFormat.format("SELECT a.attname ASfield,t.typname AS type,col_description(a.attrelid,a.attnum) as comment,null as column_precision,null as column_scale,null as Char_Length,a.attnotnullFROM pg_class c,pg_attributea,pg_type tWHERE c.relname = {0} and a.attnum > 0and a.attrelid = c.oid and a.atttypid = t.oidORDER BY a.attnum ", new Object[] {
TableConvert.getV(tableName.toLowerCase())
});
if(CodeResourceUtil.DATABASE_TYPE.equals("sqlserver"))
sql = MessageFormat.format("select cast(a.name as varchar(50)) column_name,cast(b.name as varchar(50)) data_type,cast(e.value as varchar(200)) comment,cast(ColumnProperty(a.object_id,a.Name,'''Precision''') as int) num_precision,cast(ColumnProperty(a.object_id,a.Name,'''Scale''') as int) num_scale,a.max_length,(case when a.is_nullable=1 then '''y''' else '''n''' end) nullable from sys.columns a left join sys.types b on a.user_type_id=b.user_type_id left join sys.objects c on a.object_id=c.object_id and c.type='''U''' left join sys.extended_properties e on e.major_id=c.object_id and e.minor_id=a.column_id and e.class=1 where c.name={0}", new Object[] {
TableConvert.getV(tableName.toLowerCase())
});
rs = stmt.executeQuery(sql);
rs.last();
int fieldNum = rs.getRow();
if(fieldNum > 0)
return true;
}
catch(Exception e)
{
e.printStackTrace();
return false;
}
return false;
}
代码生成器的配置文件修改 了吗?再确认链接的是本地库,还是远程库 admin 发表于 2016-5-3 09:26 static/image/common/back.gif
代码生成器的配置文件修改 了吗?再确认链接的是本地库,还是远程库
如果是远程库的话有哪里要改的吗 因为表名做了tableName.toUpperCase()处理,需要确认一下mysql数据库是否设置了大小写敏感
数据库配置:
用root帐号登录后,在/etc/my.cnf 中的后添加添加lower_case_table_names=1,重启MYSQL服务,这时已设置成功:不区分表名的大小写 楼上正解:lol,用了这个方法解决了 lower_case_table_names can only be configured when initializing the server. Changing the lower_case_table_names setting after the server is initialized is prohibited.
以上为官方说明,目前已经不支持 lower_case_table_names=1 参数修改了,只有初始化数据库修改一条路。
而生产数据库呀,岂能随便初始化。
真是好大的一个坑,不知道jeecg里的表名为什么不能调整成小写呢?
页:
[1]