TestPhoenix.java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;
public class TestPhoenix {
/**
* @author yinkaipeng
* 访问kerberos下的Phoenix
*/
public static void main(String[] args) throws Throwable {
try {
Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
} catch (Exception e) {
e.printStackTrace();
}
System.setProperty("java.security.krb5.conf", "D:\\krb5.conf");
Properties pps = System.getProperties();
pps.setProperty("hbase.zookeeper.quorum", "10.1.236.51");
pps.setProperty("hbase.master.kerberos.principal", "hbase/_HOST@yinkp");
pps.setProperty("hbase.regionserver.kerberos.principal", "hbase/_HOST@yinkp");
pps.setProperty("phoenix.queryserver.kerberos.principal", "HTTP/_HOST@yinkp");
pps.setProperty("hbase.security.authentication", "kerberos");
pps.setProperty("hadoop.security.authentication", "kerberos");
pps.setProperty("zookeeper.znode.parent", "/hbase-secure");
String url = "jdbc:phoenix:10.1.236.51:2181:/hbase-secure:test/host@yinkp:D:\\test.keytab";
Connection conn = DriverManager.getConnection(url,pps);
Statement statement = conn.createStatement();
String sql = "select * from test.person ";
long time = System.currentTimeMillis();
ResultSet rs = statement.executeQuery(sql);
while (rs.next()) {
int IDCARDNUM = rs.getInt("IDCARDNUM");
String NAME = rs.getString("NAME");
String AGE = rs.getString("AGE");
String SEX = rs.getString("SEX");
System.out.println("IDCARDNUM:"+IDCARDNUM+"NAME:"+NAME+"AGE:"+AGE+"SEX:"+SEX);
}
long timeUsed = System.currentTimeMillis() - time;
System.out.println("time " + timeUsed + "mm");
rs.close();
statement.close();
conn.close();
}
}
网友评论