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
...全文
423 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
This book is divided into five major parts. In part 1, “Getting started with ORM,” we discuss the fundamentals behind object/ relational mapping. We walk through a hands-on tutorial to get you started with your first Hibernate project. We look at Java application design for domain models and at the options for creating object/relational mapping metadata. Part 2, “Mapping strategies,” focuses on Java classes and their properties, and how they map to SQL tables and columns. We explore all basic and advanced mapping options in Hibernate and Java Persistence. We show you how to deal with inheritance, collections, and complex class associations. Finally, we discuss integration with legacy database schemas and some mapping strategies that are especially tricky. Part 3, “Transactional data processing,” is all about loading and storing data with Hibernate and Java Persistence. We introduce the programming interfaces, how to write transactional applications, and how Hibernate can load data from the database most efficiently. With part 4, “Writing queries,” we introduce the data query features and cover query languages and APIs in detail. Not all chapters in this part are written in a tutorial style; we expect you’ll browse this part of the book frequently when building an application and looking up a solution for a particular query problem. In part 5, “Building applications,” we discuss the design and implementation of layered and conversation-aware Java database applications. We discuss the most common design patterns that are used with Hibernate, such as the Data Access Object (DAO). You see how you can test your Hibernate application easily and learn what other best practices are relevant if you work with an object/relational mapping software in web and client/server applications in general.

67,543

社区成员

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

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