Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Database \ Java to create a table in the database SYBase     - Android Service Lifecycle and usage (Programming)

- Linux security settings Basics (Linux)

- CentOS7 build GlusterFS (Linux)

- Upgrade to Linux Mint 16 petra Mint 17 Qiana (Linux)

- CentOS yum source deployment (Linux)

- How to upgrade to Oracle 11g Oracle 12c (Database)

- There are more than one server, there is reason to try cloud operating system (Server)

- Java string concatenation techniques (StringBuilder tips) (Programming)

- RocketMQ Message Queuing simple deployment (Linux)

- Linux Apache server security (Linux)

- How to interactively create a Docker container (Server)

- Hackers is how the invasion and control of Things devices? (Linux)

- Nagios (centreon) monitoring LVS (Server)

- RHEL5 stalled due to power service error system can not start (Linux)

- Linux System Getting Started Learning: complete installation on Debian or Ubuntu kernel source (Linux)

- Verify the character set on MyCAT (Database)

- Linux crontab commands and detailed usage examples (Linux)

- Linux User Management (Linux)

- Linux source code to install Apache and solutions to common errors (Server)

- Ubuntu GCC, G ++ and fortran Version Switch (Linux)

 
         
  Java to create a table in the database SYBase
     
  Add Date : 2018-11-21      
         
         
         
  To create a data table in HBase by Java, you first need to import hbase-client.jar driver package. You can add dependencies in the project pom.xml configuration file:

< Dependency>
     < GroupId> org.apache.hbase < / groupId>
     < ArtifactId> hbase-client < artifactId>
     < Version> 1.1.0.1 < / version>
< Dependency>
After adding a dependency, we need to create a Configuration object and specify core-site.xml and hbase-site.xml as a resource file.

Configuration config = HBaseConfiguration.create ();
config.addResource (new Path ( "/ etc / hbase / conf / hbase-site.xml"));
config.addResource (new Path ( "/ etc / Hadoop / conf / core-site.xml"));
Also need to set parameters and values ​​hbase.zookeeper.quorum hbase.zookeeper.property.clientPort parameters in the Configuration object, these values ​​can also be found in hbase-site.xml configuration file:

Configuration config = HBaseConfiguration.create ();
config.set ( "hbase.zookeeper.quorum", "127.0.0.1");
config.set ( "hbase.zookeeper.property.clientPort", "2181");
After the Configuration object is created, and then create a connection to the Connection object HBase database, and get Admin objects of this object, it is responsible for implementing the creation of data tables:

Connection connection = ConnectionFactory.createConnection (config);
Admin admin = connection.getAdmin ();
Once you have created the Admin object can use the following code to create a data table:

String tableName = "users";

if (! admin.isTableAvailable (TableName.valueOf (tableName))) {
    HTableDescriptor hbaseTable = new HTableDescriptor (TableName.valueOf (tableName));
    hbaseTable.addFamily (new HColumnDescriptor ( "name"));
    hbaseTable.addFamily (new HColumnDescriptor ( "contact_info"));
    hbaseTable.addFamily (new HColumnDescriptor ( "personal_info"));
    admin.createTable (hbaseTable);
}
Whether there will be serious "users" name of the data table, if the table does not exist will create a new table, column names include: family name, contact information and personal information.

Complete the following procedures:

package com.wordpress.khodeprasad;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

/ **
* @author Prasad Khode
*
* /
public class CreateTable {

    public static void main (String [] args) {
        CreateTable object = new CreateTable ();
        object.createTable ();
    }

    public void createTable () {
        Configuration config = HBaseConfiguration.create ();
        config.set ( "hbase.zookeeper.quorum", "127.0.0.1");
        config.set ( "hbase.zookeeper.property.clientPort", "2181");

        Connection connection = null;
        Admin admin = null;

        try {
            connection = ConnectionFactory.createConnection (config);
            admin = connection.getAdmin ();

            String tableName = "users";

            if (! admin.isTableAvailable (TableName.valueOf (tableName))) {
                HTableDescriptor hbaseTable = new HTableDescriptor (TableName.valueOf (tableName));
                hbaseTable.addFamily (new HColumnDescriptor ( "name"));
                hbaseTable.addFamily (new HColumnDescriptor ( "contact_info"));
                hbaseTable.addFamily (new HColumnDescriptor ( "personal_info"));
                admin.createTable (hbaseTable);
            }
        } Catch (Exception e) {
            e.printStackTrace ();
        } Finally {
            try {
                if (admin! = null) {
                    admin.close ();
                }

                if (connection! = null &&! connection.isClosed ()) {
                    connection.close ();
                }
            } Catch (Exception e2) {
                e2.printStackTrace ();
            }
        }
    }
}
     
         
         
         
  More:      
 
- Linux System Getting Started Learning: rename multiple files in Linux (Linux)
- Linux operation and maintenance of the automated installation and deployment RHEL7.0 Cobbler (Linux)
- Servlet 3.0 interfaces of AsyncListener (Programming)
- How to use the command line ftp upload and download files (Linux)
- Android Studio Personalization (Linux)
- Linux security configuration (Linux)
- Phoenix agents use P2P WebRTC development (Programming)
- Ubuntu Locale configuration problem solving Can not set LC_CTYPE (Linux)
- Setting CentOS firewall open port (Linux)
- Deploy Mono 4 and Jexus 5.6 on CentOS7 (Server)
- A brief introduction to some important Docker commands (Server)
- Linux account related documents Interpretation (Linux)
- How to enhance the security of Linux systems (Linux)
- The PostgreSQL database pg_dump command line does not enter a password method (Database)
- To install the Ubuntu Touch emulator on Ubuntu (Linux)
- To generate a certificate using OpenSSL under Linux (Server)
- Installation of network monitoring ntopng under CentOS 6.4 (Linux)
- Oracle 12c In-Memory Study (Database)
- MySQL Error Code Complete (Database)
- Linux system using the command line shutdown or restart (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.