hibernate中如何执行show tables

xiaozhao32 2010-08-11 12:06:05
如题:
Session session = HibernateSessionFactory.getSession();
List<?> list = session.createSQLQuery("show tables").list();
System.out.println(list);
报错:
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2231)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
at org.hibernate.loader.Loader.list(Loader.java:2120)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:312)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1722)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:175)
at com.zy.util.HibernateSessionFactory.main(HibernateSessionFactory.java:114)
Caused by: java.sql.SQLException: Column 'TABLE_NAME' not found.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1093)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5488)
at org.hibernate.type.StringType.get(StringType.java:41)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:184)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:210)
at org.hibernate.loader.custom.CustomLoader$ScalarResultColumnProcessor.extract(CustomLoader.java:497)
at org.hibernate.loader.custom.CustomLoader$ResultRowProcessor.buildResultRow(CustomLoader.java:443)
at org.hibernate.loader.custom.CustomLoader.getResultColumnOrRow(CustomLoader.java:340)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:629)
at org.hibernate.loader.Loader.doQuery(Loader.java:724)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2228)
... 7 more
...全文
417 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
haldis 2012-05-28
  • 打赏
  • 举报
回复
mysql中是可以这样写的,周末在家里电脑上是可以运行的,今天到公司就报这个错了,是不是和版本有关呢?
believefym 2010-08-11
  • 打赏
  • 举报
回复
hibernate好像不是为这种需求设计的吧。。。。
xiaozhao32 2010-08-11
  • 打赏
  • 举报
回复
看来也只能用数据源 才能分开查询不同的数据库表结构了 谢谢5楼
humijnjie227 2010-08-11
  • 打赏
  • 举报
回复
不能这样查的。呵呵。。要用数据源查。。。
classlj 2010-08-11
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 duyu1025 的回复:]
Java code

List<?> list = session.createSQLQuery("show tables").list();





有这种SQL语句??

查询当前用户的所有表:
select table_name from user_tables
[/Quote]


MYSQL show tables;

Oracle select * from tab;
xiaozhao32 2010-08-11
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 duyu1025 的回复:]

Java code

List<?> list = session.createSQLQuery("show tables").list();





有这种SQL语句??

查询当前用户的所有表:
select table_name from user_tables
[/Quote]
那是oracle用法,不是mysql
duyu1025 2010-08-11
  • 打赏
  • 举报
回复

List<?> list = session.createSQLQuery("show tables").list();




有这种SQL语句??

查询当前用户的所有表:
select table_name from user_tables

67,550

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧