Guest User

Untitled

a guest
Mar 8th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.48 KB | None | 0 0
  1. import java.sql.*;
  2. public class DrillJDBCExample {
  3. static final String JDBC_DRIVER = "org.apache.drill.jdbc.Driver";
  4. static final String DB_URL = "jdbc:drill:drillbit=localhost:";//"jdbc:drill:zk=localhost:2181";
  5. //"jdbc:drill:drillbit=localhost";
  6.  
  7.  
  8. static final String USER = "admin";
  9. static final String PASS = "admin";
  10.  
  11.  
  12. public static void main(String[] args) throws ClassNotFoundException, SQLException {
  13. /* Class.forName("org.apache.drill.jdbc.Driver");
  14. Connection connection =DriverManager.getConnection("jdbc:drill:drillbit=127.0.0.1:8765");
  15. Statement st = connection.createStatement();
  16. ResultSet rs = st.executeQuery("SELECT * from cp.`employee`");
  17. while(rs.next()){
  18. System.out.println(rs.getString(1));
  19. }
  20. }*/
  21. Connection conn = null;
  22. Statement stmt = null;
  23. try{
  24. Class.forName(JDBC_DRIVER);
  25. conn = DriverManager.getConnection(DB_URL,USER,PASS);
  26.  
  27.  
  28. stmt = conn.createStatement();
  29. // Perform a select on data in the classpath storage plugin.
  30. String sql = "select employee_id,first_name,last_name from cp.`employee.json`";
  31. ResultSet rs = stmt.executeQuery(sql);
  32.  
  33.  
  34. while(rs.next()) {
  35. int id = rs.getInt("employee_id");
  36. String first = rs.getString("first_name");
  37. String last = rs.getString("last_name");
  38.  
  39.  
  40. System.out.print("ID: " + id);
  41. System.out.print(", First: " + first);
  42. System.out.println(", Last: " + last);
  43. }
  44.  
  45.  
  46. rs.close();
  47. stmt.close();
  48. conn.close();
  49. } catch(SQLException se) {
  50. //Handle errors for JDBC
  51. se.printStackTrace();
  52. } catch(Exception e) {
  53. //Handle errors for Class.forName
  54. e.printStackTrace();
  55. } finally {
  56. try{
  57. if(stmt!=null)
  58. stmt.close();
  59. } catch(SQLException se2) {
  60. }
  61. try {
  62. if(conn!=null)
  63. conn.close();
  64. } catch(SQLException se) {
  65. se.printStackTrace();
  66. }
  67. }
  68. }
  69.  
  70. }
  71.  
  72. SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
  73. SLF4J: Defaulting to no-operation (NOP) logger implementation
  74. SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
  75. java.sql.SQLException: Failure in connecting to Drill: oadd.org.apache.drill.exec.rpc.RpcException: HANDSHAKE_COMMUNICATION : Channel closed /127.0.0.1:60181 <--> localhost/127.0.0.1:8765.
  76. at org.apache.drill.jdbc.impl.DrillConnectionImpl.<init>(DrillConnectionImpl.java:162)
  77. at org.apache.drill.jdbc.impl.DrillJdbc41Factory.newDrillConnection(DrillJdbc41Factory.java:64)
  78. at org.apache.drill.jdbc.impl.DrillFactory.newConnection(DrillFactory.java:69)
  79. at oadd.net.hydromatic.avatica.UnregisteredDriver.connect(UnregisteredDriver.java:126)
  80. at org.apache.drill.jdbc.Driver.connect(Driver.java:72)
  81. at java.sql.DriverManager.getConnection(Unknown Source)
  82. at java.sql.DriverManager.getConnection(Unknown Source)
  83. at com.mapr.drill.DrillJDBCExample.main(DrillJDBCExample.java:29)
  84. Caused by: oadd.org.apache.drill.exec.rpc.RpcException: HANDSHAKE_COMMUNICATION : Channel closed /127.0.0.1:60181 <--> localhost/127.0.0.1:8765.
  85. at oadd.org.apache.drill.exec.client.DrillClient$FutureHandler.connectionFailed(DrillClient.java:675)
  86. at oadd.org.apache.drill.exec.rpc.user.QueryResultHandler$ChannelClosedHandler.connectionFailed(QueryResultHandler.java:389)
  87. at oadd.org.apache.drill.exec.rpc.BasicClient$ConnectionMultiListener$HandshakeSendHandler.failed(BasicClient.java:254)
  88. at oadd.org.apache.drill.exec.rpc.RequestIdMap$RpcListener.setException(RequestIdMap.java:134)
  89. at oadd.org.apache.drill.exec.rpc.RequestIdMap$SetExceptionProcedure.apply(RequestIdMap.java:74)
  90. at oadd.org.apache.drill.exec.rpc.RequestIdMap$SetExceptionProcedure.apply(RequestIdMap.java:64)
  91. at oadd.com.carrotsearch.hppc.IntObjectHashMap.forEach(IntObjectHashMap.java:692)
  92. at oadd.org.apache.drill.exec.rpc.RequestIdMap.channelClosed(RequestIdMap.java:58)
  93. at oadd.org.apache.drill.exec.rpc.RemoteConnection.channelClosed(RemoteConnection.java:175)
  94. at oadd.org.apache.drill.exec.rpc.RpcBus$ChannelClosedHandler.operationComplete(RpcBus.java:167)
  95. at oadd.org.apache.drill.exec.rpc.RpcBus$ChannelClosedHandler.operationComplete(RpcBus.java:146)
  96. at oadd.io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:680)
  97. at oadd.io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:567)
  98. at oadd.io.netty.util.concurrent.DefaultPromise.trySuccess(DefaultPromise.java:406)
  99. at oadd.io.netty.channel.DefaultChannelPromise.trySuccess(DefaultChannelPromise.java:82)
  100. at oadd.io.netty.channel.AbstractChannel$CloseFuture.setClosed(AbstractChannel.java:943)
  101. at oadd.io.netty.channel.AbstractChannel$AbstractUnsafe.doClose0(AbstractChannel.java:592)
  102. at oadd.io.netty.channel.AbstractChannel$AbstractUnsafe.close(AbstractChannel.java:584)
  103. at oadd.io.netty.channel.DefaultChannelPipeline$HeadContext.close(DefaultChannelPipeline.java:1099)
  104. at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeClose(AbstractChannelHandlerContext.java:615)
  105. at oadd.io.netty.channel.AbstractChannelHandlerContext.close(AbstractChannelHandlerContext.java:600)
  106. at oadd.io.netty.channel.ChannelOutboundHandlerAdapter.close(ChannelOutboundHandlerAdapter.java:71)
  107. at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeClose(AbstractChannelHandlerContext.java:615)
  108. at oadd.io.netty.channel.AbstractChannelHandlerContext.close(AbstractChannelHandlerContext.java:600)
  109. at oadd.io.netty.channel.ChannelDuplexHandler.close(ChannelDuplexHandler.java:73)
  110. at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeClose(AbstractChannelHandlerContext.java:615)
  111. at oadd.io.netty.channel.AbstractChannelHandlerContext.close(AbstractChannelHandlerContext.java:600)
  112. at oadd.io.netty.channel.AbstractChannelHandlerContext.close(AbstractChannelHandlerContext.java:466)
  113. at oadd.org.apache.drill.exec.rpc.RpcExceptionHandler.exceptionCaught(RpcExceptionHandler.java:39)
  114. at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:275)
  115. at oadd.io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:253)
  116. at oadd.io.netty.channel.ChannelInboundHandlerAdapter.exceptionCaught(ChannelInboundHandlerAdapter.java:131)
  117. at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:275)
  118. at oadd.io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:253)
  119. at oadd.io.netty.channel.ChannelInboundHandlerAdapter.exceptionCaught(ChannelInboundHandlerAdapter.java:131)
  120. at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:275)
  121. at oadd.io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:253)
  122. at oadd.io.netty.channel.ChannelInboundHandlerAdapter.exceptionCaught(ChannelInboundHandlerAdapter.java:131)
  123. at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:275)
  124. at oadd.io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:253)
  125. at oadd.io.netty.channel.ChannelHandlerAdapter.exceptionCaught(ChannelHandlerAdapter.java:79)
  126. at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:275)
  127. at oadd.io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:253)
  128. at oadd.io.netty.channel.ChannelInboundHandlerAdapter.exceptionCaught(ChannelInboundHandlerAdapter.java:131)
  129. at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:275)
  130. at oadd.io.netty.channel.AbstractChannelHandlerContext.notifyHandlerException(AbstractChannelHandlerContext.java:809)
  131. at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:341)
  132. at oadd.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:324)
  133. at oadd.io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:242)
  134. at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:339)
  135. at oadd.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:324)
  136. at oadd.io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)
  137. at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:339)
  138. at oadd.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:324)
  139. at oadd.io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:847)
  140. at oadd.io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
  141. at oadd.io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
  142. at oadd.io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
  143. at oadd.io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
  144. at oadd.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
  145. at oadd.io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:111)
  146. at java.lang.Thread.run(Unknown Source)
  147. Caused by: oadd.org.apache.drill.exec.rpc.ChannelClosedException: Channel closed /127.0.0.1:60181 <--> localhost/127.0.0.1:8765.
  148. at oadd.org.apache.drill.exec.rpc.RpcBus$ChannelClosedHandler.operationComplete(RpcBus.java:166)
  149. ... 52 more
Add Comment
Please, Sign In to add comment