Hive insertion using java application
<p>I am trying to insert rows into Hive using JavaApplication.Hive cli is working properly and able to create,insert,drop tables.</p>

<p>my code is like this,</p>

<pre><code>    import java.sql.SQLException;
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import java.sql.DriverManager;
    import org.apache.hive.jdbc.HiveDriver;;


    public class HiveInsert {
       private static String driverName = "org.apache.hive.jdbc.HiveDriver";

       public static void main(String[] args) throws SQLException, ClassNotFoundException {

          // Register driver and create driver instance
          Class.forName(driverName);

          // get connection
          Connection con = DriverManager.getConnection("jdbc:hive2://192.168.1.136:10000/test", "", "");

          // create statement
          Statement stmt = con.createStatement();

          // execute statement
         stmt.executeQuery("insert into test.sample(id,name) values(11,'ppl')");
         ResultSet res = stmt.executeQuery("select * from test.sample");
          System.out.println("Result:");
          System.out.println(" ID \t EID \t Name ");

          while (res.next()) {
             System.out.println(res.getInt(1) + " " + res.getInt(2)+ " " + res.getString(3));
          }
          con.close();
       }

}
</code></pre>

<p>but I am this error,</p>

<pre><code>Exception in thread "main" java.sql.SQLException: Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask
    at org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:296)
    at org.apache.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:392)
    at HiveInsert.main(HiveInsert.java:24)
</code></pre>

<p>anybody have any solution for this error,please share with me.Is there any other way to insert into hive using java application.Any help is appreciated.</p>

<pre><code>Exception in thread "main" java.sql.SQLException: Could not open client transport with JDBC Uri: jdbc:hive2://hostname:10000/test: java.net.ConnectException: Connection refused: connect
    at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:231)
    at org.apache.hive.jdbc.HiveConnection.&lt;init&gt;(HiveConnection.java:176)
    at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at HiveInsert.main(HiveInsert.java:18)
Caused by: org.apache.thrift.transport.TTransportException: java.net.ConnectException: Connection refused: connect
    at org.apache.thrift.transport.TSocket.open(TSocket.java:187)
    at org.apache.thrift.transport.TSaslTransport.open(TSaslTransport.java:266)
    at org.apache.thrift.transport.TSaslClientTransport.open(TSaslClientTransport.java:37)
    at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:204)
    ... 5 more
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at org.apache.thrift.transport.TSocket.open(TSocket.java:182)
    ... 8 more
</code></pre>