Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

Exception in thread "main" java.sql.SQLException: org.apache.thrift.transport.TTransportException

avatar

Hi,

 

I am getting the following error while connecting to Hive using Jdbc with org.apache.hadoop.hive.jdbc.HiveDriver.

Help Me to solve this.

Exception in thread "main" java.sql.SQLException: org.apache.thrift.transport.TTransportException
at org.apache.hadoop.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:191)
at org.apache.hadoop.hive.jdbc.HiveStatement.execute(HiveStatement.java:127)
at org.apache.hadoop.hive.jdbc.HiveConnection.configureConnection(HiveConnection.java:126)
at org.apache.hadoop.hive.jdbc.HiveConnection.<init>(HiveConnection.java:121)
at org.apache.hadoop.hive.jdbc.HiveDriver.connect(HiveDriver.java:104)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at com.cloudera.hive.HiveConnectDB.main(HiveConnectDB.java:18)






Thanks
SudheerKota
1 ACCEPTED SOLUTION

avatar
Super Collaborator

Hi,

 

Maybe you could share the java source code doing the connection ?

Here is a really small working sample :

 

 

public class ManageHive {

private static String driverName = "org.apache.hive.jdbc.HiveDriver";
private static Logger logger = Logger.getLogger(ManageHive.class);

public static Connection getConnection(LoadProperties prop, String user) throws ClassNotFoundException, SQLException {

String hiveJdbc = prop.getPropertyByName("hive_jdbc");

try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
e.printStackTrace();
throw e;
}
Connection conn2 = DriverManager.getConnection(hiveJdbc+"/extraction", user, "");
return conn2;
}

public static void execSql(LoadProperties prop, String user, String sql) throws SQLException, ClassNotFoundException {

Connection maConn = getConnection(prop,user);
Statement stmt = maConn.createStatement();

int result = stmt.executeUpdate(sql);
if ( result == Statement.EXECUTE_FAILED ) {
throw new SQLException("Erreur d'execution.");
}
}
}

 

 

 

View solution in original post

2 REPLIES 2

avatar
Super Collaborator

Hi,

 

Maybe you could share the java source code doing the connection ?

Here is a really small working sample :

 

 

public class ManageHive {

private static String driverName = "org.apache.hive.jdbc.HiveDriver";
private static Logger logger = Logger.getLogger(ManageHive.class);

public static Connection getConnection(LoadProperties prop, String user) throws ClassNotFoundException, SQLException {

String hiveJdbc = prop.getPropertyByName("hive_jdbc");

try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
e.printStackTrace();
throw e;
}
Connection conn2 = DriverManager.getConnection(hiveJdbc+"/extraction", user, "");
return conn2;
}

public static void execSql(LoadProperties prop, String user, String sql) throws SQLException, ClassNotFoundException {

Connection maConn = getConnection(prop,user);
Statement stmt = maConn.createStatement();

int result = stmt.executeUpdate(sql);
if ( result == Statement.EXECUTE_FAILED ) {
throw new SQLException("Erreur d'execution.");
}
}
}

 

 

 

avatar

Hi Thanks for the Reply,I solved the issue.I have used following driver

public static String driverName = "com.cloudera.hive.jdbc41.HS1Driver";and added other required jars too.






Thanks
SudheerKota