In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
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.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.