I'm trying to create table in hive with java. I found
java.sql.SQLException: org.apache.thrift.transport.TTransportException
while executing my code.
Here is my code
public void createTable(String tableName) {
try{
Statement stat = con.createStatement();
String QueryString = "CREATE TABLE '"+tableName+"'(User_Id INTEGER NOT NULL AUTO_INCREMENT, " + "User_Name VARCHAR(25), UserId VARCHAR(20), User_Pwd VARCHAR(15), primary key(User_Id))";
a = stat.executeUpdate(QueryString);
if(a==1){
System.out.println(a);
System.out.println("Table has been created");
}
}catch(Exception e){
System.out.println(e);}
}
Why this exception is thrown and how can i fix it.?
It is a very generic error message describing that the hiveserver is having a problem and suggesting you to take a look at the Hive logs. If you access the hive logs and find the exception call stack, you can find the root cause or if you share the exception, I might be able to help you.
Most common problems I have seen as:
Issues with meta store related with concurrency
When you start hive server as $hive --service yourhiveserver and keep it running for days and then run your code, it is possible that your connection is broker to server and you will get exact same error. If you reconnect to server and this error will go away. This is only because after some time wait_time expired and disconnect happen.
Port specific errors
Be sure to setup an open Port for your Hive Server and set it as below before starting hive server:
$export HIVE_PORT=10000
$hive --service hiveserver
$ _run_your_code
There could be other reasons, however your best option is to check the call stack in hive logs to root cause and solve the problem.