내 프로그램을 실행하기 위해 gradle을 사용합니다. 샘플 코드는 https://github.com/onefoursix/Cloudera-Impala-JDBC-Example 을 참조 합니다.
그리고 실패없이 저장소에서 예제를 실행할 수 있습니다.
// Apply the java plugin to add support for Java
apply plugin: 'java'
apply plugin: 'application'
mainClassName = "com.my.impala.fetcher.Fetcher"
// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
mavenCentral()
maven {
url "https://repository.cloudera.com/artifactory/cloudera-repos/"
}
}
run {
if (project.hasProperty("params")) {
args params
// args Eval.me(params)
}
}
test {
testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
}
}
// In this section you declare the dependencies for your production and test code
dependencies {
// The production code uses the SLF4J logging API at compile time
compile 'org.slf4j:slf4j-api:1.7.7'
compile 'org.apache.hadoop:hadoop-client:2.6.0-cdh5.4.4.1'
compile 'org.json:json:20140107'
compile 'org.apache.hive:hive-jdbc:1.1.0'
}
샘플 코드는 다음과 같습니다.
Connection con = null;
ResultSet rs = null;
try {
Class.forName(JDBC_DRIVER_NAME);
con = DriverManager.getConnection(CONNECTION_HOST);
Statement stmt = con.createStatement();
rs = stmt.executeQuery(sqlStatement);
} catch (SQLException e) {
e.printStackTrace();
System.exit(-1);
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
} finally {
try {
con.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
}
rs.next();
경우 rs.next
다음과 같은 예외가 발생합니다
org.apache.thrift.transport.TTransportException: Cannot write to null outputStream
at org.apache.thrift.transport.TIOStreamTransport.write(TIOStreamTransport.java:142)
at org.apache.thrift.protocol.TBinaryProtocol.writeI32(TBinaryProtocol.java:178)
at org.apache.thrift.protocol.TBinaryProtocol.writeMessageBegin(TBinaryProtocol.java:106)
at org.apache.thrift.TServiceClient.sendBase(TServiceClient.java:62)
at org.apache.hive.service.cli.thrift.TCLIService$Client.send_FetchResults(TCLIService.java:495)
at org.apache.hive.service.cli.thrift.TCLIService$Client.FetchResults(TCLIService.java:487)
at org.apache.hive.jdbc.HiveQueryResultSet.next(HiveQueryResultSet.java:360)
at com.my.impala.fetcher.Fetcher.main(Fetcher.java:54)
Exception in thread "main" java.sql.SQLException: Error retrieving next row
at org.apache.hive.jdbc.HiveQueryResultSet.next(HiveQueryResultSet.java:388)
at com.my.impala.fetcher.Fetcher.main(Fetcher.java:54)
Caused by: org.apache.thrift.transport.TTransportException: Cannot write to null outputStream
at org.apache.thrift.transport.TIOStreamTransport.write(TIOStreamTransport.java:142)
at org.apache.thrift.protocol.TBinaryProtocol.writeI32(TBinaryProtocol.java:178)
at org.apache.thrift.protocol.TBinaryProtocol.writeMessageBegin(TBinaryProtocol.java:106)
at org.apache.thrift.TServiceClient.sendBase(TServiceClient.java:62)
at org.apache.hive.service.cli.thrift.TCLIService$Client.send_FetchResults(TCLIService.java:495)
at org.apache.hive.service.cli.thrift.TCLIService$Client.FetchResults(TCLIService.java:487)
at org.apache.hive.jdbc.HiveQueryResultSet.next(HiveQueryResultSet.java:360)
... 1 more
내가 놓친 부분이 확실하지 않습니다.
감사합니다.
이미 연결을 끊었지만 결과를 읽을 수 없습니다. 다음 과 같이 try 블록의 끝에서 줄 rs.next()
뒤에 있어야합니다 executeQuery()
.
rs = stmt.executeQuery(sqlStatement);
while (rs.next()) {
// handle the record
}
(가) ResultSet
데이터베이스입니다 커서 는 전체 데이터 집합을 포함하지 않습니다, 당신은 그것을 통해 DB에있는 데이터에 액세스 할 수 있습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다