使用cayenne OR映射,原先在A数据库进行OR映射,具体配置及如果映射在此不详述,输出的代码如下,输出对象的一个属性列表。测试是成功的。
ServerRuntime cayenneRuntime = new ServerRuntime("cayenne-project.xml");
ObjectContext context = cayenneRuntime.getContext();
SelectQuery select1 = new SelectQuery(InfoPropriety.class);
java.util.List info = context.performQuery(select1);
for(int i=0;i<info.size();i++)
{
InfoPropriety Info= (InfoPropriety) info.get(i);
System.out.println(Info.getPropName());
}
后来新建数据库,同样的代码,一直出现如下错误提示:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 '-info.info_propriety t0' at line 1
觉得非常奇怪,为什么突然就出错了呢。代码都没问题啊,但是提示是SQL语句中出问题了。
然后在查询分析器中输入
SELECT t0.propCode, t0.propName, t0.propId FROM smatx-info.info_propriety t0
这时候就发现问题了。问题出在数据库的命名上,"-"这个符号在SQL中是属于关键字,是不能用来命名数据库表的。然后把-改成_,即smartx_info问题迎刃而解。