How to use java api to send hbase shell command directly like jdbc?
public static void main(String args[]) {
// get Connection to connect hbase
Connection conn = ....;
// hbase shell command
String cmd = "get 't1','r1'";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(cmd);
while(rs.next()) {
...
}
}
if there is no java api for this, is there another way to achieve the goal?
Please note that, Phoenix can execute queries in jdbc style... If you want to execute get commands then you can use Hbase java client api directly. Its not common practice to execute from java through shell.
If you still want to do it from java prepare gets or list of commands in a text file and using
RunTime.execute
you can executehbase shell <yourhbaseshelllcommands.txt>
see my answer1 or answer2 this to do that. I have done that for spark submit and mapreduce jobs. you can use the same method for your hbase shell execution which was described above.
To access Hbase in SQL way you can use Phoenix. - https://phoenix.apache.org/faq.html - see this
Also you can check with Impala or hive.
JDBC Client Driver :
If you are using maven below are dependencies...