0% found this document useful (0 votes)
83 views2 pages

Create Hive Database Guide

The document discusses how to create databases in Hive. It provides the CREATE DATABASE statement syntax and explains how to use it to create a new database. It also shows how to list existing databases and provides a Java example to programmatically create a Hive database.

Uploaded by

boxbe9876
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views2 pages

Create Hive Database Guide

The document discusses how to create databases in Hive. It provides the CREATE DATABASE statement syntax and explains how to use it to create a new database. It also shows how to list existing databases and provides a Java example to programmatically create a Hive database.

Uploaded by

boxbe9876
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

4/2/24, 7:28 AM Hive - Create Database

Hive - Create Database

Hive is a database technology that can define databases and tables to analyze
structured data. The theme for structured data analysis is to store the data in a
tabular manner, and pass queries to analyze it. This chapter explains how to create
Hive database. Hive contains a default database named default.

Create Database Statement


Create Database is a statement used to create a database in Hive. A database in
Hive is a namespace or a collection of tables. The syntax for this statement is as
follows:

CREATE DATABASE|SCHEMA [IF NOT EXISTS] <database name>

Here, IF NOT EXISTS is an optional clause, which notifies the user that a database
with the same name already exists. We can use SCHEMA in place of DATABASE in
this command. The following query is executed to create a database named userdb:

hive> CREATE DATABASE [IF NOT EXISTS] userdb;

or

hive> CREATE SCHEMA userdb;

The following query is used to verify a databases list:

hive> SHOW DATABASES;


default
userdb

JDBC Program

https://www.tutorialspoint.com/hive/hive_create_database.htm 1/2
4/2/24, 7:28 AM Hive - Create Database

The JDBC program to create a database is given below.

import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;

public class HiveCreateDb {


private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver

public static void main(String[] args) throws SQLException {


// Register driver and create driver instance

Class.forName(driverName);
// get connection

Connection con = DriverManager.getConnection("jdbc:hive://localhost:100


Statement stmt = con.createStatement();

stmt.executeQuery("CREATE DATABASE userdb");


System.out.println(“Database userdb created successfully.”);

con.close();
}
}

Save the program in a file named HiveCreateDb.java. The following commands are
used to compile and execute this program.

$ javac HiveCreateDb.java
$ java HiveCreateDb

Output:

Database userdb created successfully.

https://www.tutorialspoint.com/hive/hive_create_database.htm 2/2

You might also like