package com;
import java.sql.*;
import java.util.HashMap;
public class App
{
private static Connection connect;
private static Statement statement;
private static PreparedStatement preparedStatement;
private static ResultSet resultSet;
private static String serverURL;
static {
connect = null;
statement = null;
preparedStatement = null;
resultSet = null;
serverURL = "jdbc:phoenix:12.234.56.78:2181:/hbase";
}
public static Connection connect() throws Exception {
Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
connect = DriverManager.getConnection(serverURL);
return connect;
}
public static HashMap<Integer, String> getSelect() throws Exception {
connect = connect();
final HashMap<Integer, String> record = new HashMap<Integer, String>();
preparedStatement = connect.prepareStatement("select * from TEST;");
resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
Integer myKey = resultSet.getInt(1);
String myColumn = resultSet.getString(2);
record.put(myKey, myColumn);
}
connect.close();
return record;
}
public static void main( String[] args )
{
try {
HashMap<Integer, String> record = new HashMap<Integer, String>();
record = getSelect();
System.out.println(record);
} catch (Exception e) {
e.printStackTrace();
}
}
}