代码实例
package oa.epoint.com.phoenix;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class PhoenixTest {
private static String driver = "org.apache.phoenix.jdbc.PhoenixDriver";
public static void main(String[] args) throws SQLException {
try {
Class.forName(driver);
System.out.println("驱动加载成功");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Statement stmt = null;
ResultSet rs = null;
System.out.println("准备数据库连接");
Connection con = DriverManager.getConnection("jdbc:phoenix:100.2.5.1:2181:/hbase-unsecure");
System.out.println("连接成功");
stmt = con.createStatement();
stmt.executeUpdate("drop table if exists test5");
stmt.executeUpdate("create table if not exists test5 (id BIGINT not null primary key,name varchar)");
stmt.executeUpdate("UPSERT INTO test5 VALUES(123,'xubin')");
con.commit();
String sql = "select * from test5";
rs = stmt.executeQuery(sql);
while (rs.next()) {
System.out.print("id:"+rs.getInt("id"));
System.out.println(",name:"+rs.getString("name"));
}
stmt.close();
con.close();
}
}