java使用jdbc调用hive出现The query did not generate a result set!

使用java通过jdbc调用hive,执行hive sql时出现如下异常:

Exception in thread "main" java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: org.iq80.leveldb.DBException: java.sql.SQLException: The query did not generate a result set!
	at cn.wanghy.util.HiveTools.listTables(HiveTools.java:96)
	at cn.why.gd.FileSize.main(FileSize.java:44)
	... 5 more
Caused by: java.sql.SQLException: The query did not generate a result set!
	at org.apache.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:393)
	at cn.wanghy.util.HiveTools.listTables(HiveTools.java:89)
	... 6 more

错误代码如下:

stmt.executeQuery("use database")

引起异常原因:executeQuery()方法支持的是增删改查等DML语句,对于DDL 需要调用execute()来执行.
正确代码如下:

stmt.execute("use database")

你可能感兴趣的:(Hive,Java)