Get the App
SLTechnology News&Howtos  ›  Servers  › 

What is the JAVA JDBC operation of apache phoenix?

Shulou Source: shulou.com Published: 2022-06-01 00:28:07 10月31日 Update

Apache phoenix JAVA JDBC operation is how, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

Introduce jar to pom org.apache.hadoop hadoop-client 2.5.2 org.apache.hbase hbase-client 1.0.1.1 org.apache.phoenix phoenix-core 4.4.0-HBase-1.0 Create a tool class import org.apache.log4j.Logger Import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;/** * provides a standard JDBC connection using Phoenix HBase * @ author Chenj * / public class PhoenixHelper {private static final Logger LOG = Logger.getLogger (PhoenixHelper.class); private static final String JDBC_DRIVER_CLASS = "org.apache.phoenix.jdbc.PhoenixDriver" / / the / hbase in jdbc:phoenix:192.168.1.19:2181:/hbase is the root directory where HBase is registered to zooKeeper. For example, if you use the zooKeeper that comes with HBase, the default is "hbase" private static final String JDBC_URL = "jdbc:phoenix:192.168.1.19:2181:/hbase"; public static Connection getConn () {try {/ / register Driver Class.forName (JDBC_DRIVER_CLASS) / / return Connection object return DriverManager.getConnection (JDBC_URL);} catch (SQLException | ClassNotFoundException e) {e.printStackTrace (); LOG.error ("failed to get connection!"); return null }} public static void closeConn (Connection conn) {try {if (! conn.isClosed ()) conn.close ();} catch (SQLException e) {e.printStackTrace (); LOG.error ("failed to close connection!");} Test import org.junit.Before;import org.junit.Test;import java.sql.Connection Import java.sql.PreparedStatement;import java.sql.SQLException;/** * create table test * @ author Chenj * / public class TableTest {Connection conn = null; String sql = "CREATE TABLE IF NOT EXISTS user (" + "username VARCHAR NOT NULL," + "password VARCHAR," + "age INTEGER NOT NULL CONSTRAINT my_pk PRIMARY KEY (username, age))" @ Before public void init () {conn = PhoenixHelper.getConn ();} @ Test public void createTable () throws SQLException {PreparedStatement preparedStatement = conn.prepareStatement (sql); preparedStatement.execute (); PhoenixHelper.closeConn (conn);} @ Test public void dropTable () throws SQLException {PreparedStatement preparedStatement = conn.prepareStatement ("drop table user"); preparedStatement.execute (); PhoenixHelper.closeConn (conn) }} is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Tags: Help testing clarity content for this objects tools articles novices more standards root directory knowledge industry information information channels problems requirements channels into one Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Linux Microsoft macOS Shulou Technology