1.代码如下
String url = "jdbc:hive2://master135:10000/default"; String user = "root"; String pwd = "root"; String driverName = "org.apache.hive.jdbc.HiveDriver"; Class.forName(driverName); Connection conn = DriverManager.getConnection(url, user, pwd); System.out.println(conn);
2.异常如下
java.sql.SQLException: enabling autocommit is not supported at org.apache.hive.jdbc.HiveConnection.setAutoCommit(HiveConnection.java:1071) ~[hive-jdbc-1.1.0.jar:1.1.0] at com.alibaba.druid.filter.FilterChainImpl.connection_setAutoCommit(FilterChainImpl.java:604) [druid-1.1.3.jar:1.1.3] at com.alibaba.druid.filter.FilterAdapter.connection_setAutoCommit(FilterAdapter.java:985) ~[druid-1.1.3.jar:1.1.3] at com.alibaba.druid.filter.FilterChainImpl.connection_setAutoCommit(FilterChainImpl.java:600) [druid-1.1.3.jar:1.1.3] at com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl.setAutoCommit(ConnectionProxyImpl.java:430) ~[druid-1.1.3.jar:1.1.3] at com.alibaba.druid.pool.DruidConnectionHolder.reset(DruidConnectionHolder.java:290) ~[druid-1.1.3.jar:1.1.3] at com.alibaba.druid.pool.DruidDataSource.recycle(DruidDataSource.java:1505) ~[druid-1.1.3.jar:1.1.3] at com.alibaba.druid.pool.DruidPooledConnection.recycle(DruidPooledConnection.java:324) [druid-1.1.3.jar:1.1.3] at com.alibaba.druid.filter.FilterChainImpl.dataSource_recycle(FilterChainImpl.java:4609) [druid-1.1.3.jar:1.1.3] at com.alibaba.druid.filter.stat.StatFilter.dataSource_releaseConnection(StatFilter.java:651) [druid-1.1.3.jar:1.1.3] at com.alibaba.druid.filter.FilterChainImpl.dataSource_recycle(FilterChainImpl.java:4605) [druid-1.1.3.jar:1.1.3] at com.alibaba.druid.pool.DruidPooledConnection.close(DruidPooledConnection.java:267) [druid-1.1.3.jar:1.1.3] at org.springframework.jdbc.datasource.DataSourceUtils.doCloseConnection(DataSourceUtils.java:354) [spring-jdbc-5.0.0.RELEASE.jar:5.0.0.RELEASE] at org.springframework.jdbc.datasource.DataSourceUtils.doReleaseConnection(DataSourceUtils.java:341) [spring-jdbc-5.0.0.RELEASE.jar:5.0.0.RELEASE] at org.springframework.jdbc.datasource.DataSourceUtils.releaseConnection(DataSourceUtils.java:307) [spring-jdbc-5.0.0.RELEASE.jar:5.0.0.RELEASE] at org.springframework.jdbc.datasource.DataSourceTransactionManager.doCleanupAfterCompletion(DataSourceTransactionManager.java:386) [spring-jdbc-5.0.0.RELEASE.jar:5.0.0.RELEASE] at org.springframework.transaction.support.AbstractPlatformTransactionManager.cleanupAfterCompletion(AbstractPlatformTransactionManager.java:1003) [spring-tx-5.0.0.RELEASE.jar:5.0.0.RELEASE] at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransactionManager.java:874) [spring-tx-5.0.0.RELEASE.jar:5.0.0.RELEASE] at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionManager.java:808) [spring-tx-5.0.0.RELEASE.jar:5.0.0.RELEASE] at org.springframework.test.context.transaction.TransactionContext.endTransaction(TransactionContext.java:126) [spring-test-5.0.0.RELEASE.jar:5.0.0.RELEASE] at org.springframework.test.context.transaction.TransactionalTestExecutionListener.afterTestMethod(TransactionalTestExecutionListener.java:216) [spring-test-5.0.0.RELEASE.jar:5.0.0.RELEASE] at org.springframework.test.context.TestContextManager.afterTestMethod(TestContextManager.java:435) [spring-test-5.0.0.RELEASE.jar:5.0.0.RELEASE] at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:94) [spring-test-5.0.0.RELEASE.jar:5.0.0.RELEASE] at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) [spring-test-5.0.0.RELEASE.jar:5.0.0.RELEASE] at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) [junit-4.12.jar:4.12] at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251) [spring-test-5.0.0.RELEASE.jar:5.0.0.RELEASE] at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97) [spring-test-5.0.0.RELEASE.jar:5.0.0.RELEASE] at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) [junit-4.12.jar:4.12] at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) [junit-4.12.jar:4.12] at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) [junit-4.12.jar:4.12] at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) [junit-4.12.jar:4.12] at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) [junit-4.12.jar:4.12] at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) [spring-test-5.0.0.RELEASE.jar:5.0.0.RELEASE] at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) [spring-test-5.0.0.RELEASE.jar:5.0.0.RELEASE] at org.junit.runners.ParentRunner.run(ParentRunner.java:363) [junit-4.12.jar:4.12] at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190) [spring-test-5.0.0.RELEASE.jar:5.0.0.RELEASE] at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) [.cp/:na] at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) [.cp/:na] at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) [.cp/:na] at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678) [.cp/:na] at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) [.cp/:na] at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) [.cp/:na]
3.解决方式1
下载hive-jdbc-uber-2.5.0.0-1245.jar或其它编译版本install到本地maven仓库
mvn install:install-file -Dfile=D:hivejarhive-jdbc-uber-2.5.0.0-1245.jar -DgroupId=org.apache.hive -DartifactId=hive-jdbc-uber -Dversion=2.5.0.0 -Dpackaging=jar
连接成功,不会出现异常。