|
我的开发环境:jeecg3.6.3, tomcat7,jdk7,mysql5.5.49
jeecg搭建起来,运行,创建单表,生成代码出错,报错:表在数据库中不存在
跟踪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 colstable inner join user_col_comments commentstable on colstable.column_name = commentstable.column_name where colstable.table_name = commentstable.table_name and colstable.table_name = '").append(tableName.toUpperCase()).append("'").toString();
if(CodeResourceUtil.DATABASE_TYPE.equals("postgresql"))
sql = MessageFormat.format("SELECT a.attname AS field,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.attnotnull FROM pg_class c,pg_attribute a,pg_type t WHERE c.relname = {0} and a.attnum > 0 and a.attrelid = c.oid and a.atttypid = t.oid ORDER 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;
}
|
|