derby 的配置及jdbc連線
hive-default.xml
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:derby:;databaseName=metastore_db;create=true</value> 表示使用嵌入式的derby,create為true表示自動建立資料庫,資料庫名為metastore_db
<!--<value>jdbc:derby://192.168.0.3:4567/hadoopor;create=true</value>--> 表示使用客服模式的derby,hadoopor為資料庫名,192.168.0.3為derby服務端的IP地址,而4567為服務端的埠號
<description>JDBC connect string for a JDBC metastore</description>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>org.apache.derby.jdbc.EmbeddedDriver</value> 表示使用嵌入式的derby
<!--<value>org.apache.derby.jdbc.ClientDriver</value>--> 表示使用客服模式的derby
<description>Driver class name for a JDBC metastore</description>
</property>
對於嵌入式的derby要求在hive的lib目錄下有檔案derby.jar,而對於客服模式的derby要求有derbyclient.jar檔案
如果是derby壞了,就得把metastore_db刪除就好了,不過以前的資料也沒了,我覺得測試的時候用derby還行,如果正式上線的話就不要啟動嵌入式的了,直接啟動並連線線上伺服器就ok了。不然metastore_db一加鎖,啟動了hive --service hiveserver就不能啟動hive 啟動了hive就不能啟動hive --service hiveserver。
說明:
測試的時候使用嵌入式還可以,正式環境一定要用服務端模式,否則出了問題就沒法恢復了。
可以選擇任何你熟悉的語言類作為JDBC連線:
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;
public class HiveJdbcClient {
private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
/**
* @param args
* @throws SQLException
*/
public static void main(String[] args) throws SQLException {
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(1);
}
Connection con = DriverManager.getConnection("jdbc:hive://localhost:10000/default", "", "");
Statement stmt = con.createStatement();
String tableName = "testHiveDriverTable";
stmt.executeQuery("drop table " + tableName);
ResultSet res = stmt.executeQuery("create table " + tableName + " (key int, value string)");
// show tables
String sql = "show tables '" + tableName + "'";
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
if (res.next()) {
System.out.println(res.getString(1));
}
// describe table
sql = "describe " + tableName;
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
while (res.next()) {
System.out.println(res.getString(1) + "\t" + res.getString(2));
}
// load data into table
// NOTE: filepath has to be local to the hive server
// NOTE: /tmp/a.txt is a ctrl-A separated file with two fields per line
String filepath = "/tmp/a.txt";
sql = "load data local inpath '" + filepath + "' into table " + tableName;
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
// select * query
sql = "select * from " + tableName;
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
while (res.next()) {
System.out.println(String.valueOf(res.getInt(1)) + "\t" + res.getString(2));
}
// regular hive query
sql = "select count(1) from " + tableName;
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
while (res.next()) {
System.out.println(res.getString(1));
}
}
}
接下來做的工作即是執行了:
# Then on the command-line
$ javac HiveJdbcClient.java
# To run the program in standalone mode, we need the following jars in the classpath
# from hive/build/dist/lib
# hive_exec.jar
# hive_jdbc.jar
# hive_metastore.jar
# hive_service.jar
# libfb303.jar
# log4j-1.2.15.jar
#
# from hadoop/build
# hadoop-*-core.jar
#
# To run the program in embedded mode, we need the following additional jars in the classpath
# from hive/build/dist/lib
# antlr-runtime-3.0.1.jar
# derby.jar
# jdo2-api-2.1.jar
# jpox-core-1.2.2.jar
# jpox-rdbms-1.2.2.jar
#
# as well as hive/build/dist/conf
$ java -cp $CLASSPATH HiveJdbcClient
# Alternatively, you can run the following bash script, which will seed the data file
# and build your classpath before invoking the client.
#!/bin/bash
HADOOP_HOME=/your/path/to/hadoop
HIVE_HOME=/your/path/to/hive
echo -e '1\x01foo' > /tmp/a.txt
echo -e '2\x01bar' >> /tmp/a.txt
HADOOP_CORE={{ls $HADOOP_HOME/hadoop-*-core.jar}}
CLASSPATH=.:$HADOOP_CORE:$HIVE_HOME/conf
for i in ${HIVE_HOME}/lib/*.jar ; do
CLASSPATH=$CLASSPATH:$i
done
java -cp $CLASSPATH HiveJdbcClient
http://www.iteye.com/topic/1113849
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:derby:;databaseName=metastore_db;create=true</value> 表示使用嵌入式的derby,create為true表示自動建立資料庫,資料庫名為metastore_db
<!--<value>jdbc:derby://192.168.0.3:4567/hadoopor;create=true</value>--> 表示使用客服模式的derby,hadoopor為資料庫名,192.168.0.3為derby服務端的IP地址,而4567為服務端的埠號
<description>JDBC connect string for a JDBC metastore</description>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>org.apache.derby.jdbc.EmbeddedDriver</value> 表示使用嵌入式的derby
<!--<value>org.apache.derby.jdbc.ClientDriver</value>--> 表示使用客服模式的derby
<description>Driver class name for a JDBC metastore</description>
</property>
對於嵌入式的derby要求在hive的lib目錄下有檔案derby.jar,而對於客服模式的derby要求有derbyclient.jar檔案
如果是derby壞了,就得把metastore_db刪除就好了,不過以前的資料也沒了,我覺得測試的時候用derby還行,如果正式上線的話就不要啟動嵌入式的了,直接啟動並連線線上伺服器就ok了。不然metastore_db一加鎖,啟動了hive --service hiveserver就不能啟動hive 啟動了hive就不能啟動hive --service hiveserver。
說明:
測試的時候使用嵌入式還可以,正式環境一定要用服務端模式,否則出了問題就沒法恢復了。
可以選擇任何你熟悉的語言類作為JDBC連線:
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;
public class HiveJdbcClient {
private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
/**
* @param args
* @throws SQLException
*/
public static void main(String[] args) throws SQLException {
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(1);
}
Connection con = DriverManager.getConnection("jdbc:hive://localhost:10000/default", "", "");
Statement stmt = con.createStatement();
String tableName = "testHiveDriverTable";
stmt.executeQuery("drop table " + tableName);
ResultSet res = stmt.executeQuery("create table " + tableName + " (key int, value string)");
// show tables
String sql = "show tables '" + tableName + "'";
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
if (res.next()) {
System.out.println(res.getString(1));
}
// describe table
sql = "describe " + tableName;
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
while (res.next()) {
System.out.println(res.getString(1) + "\t" + res.getString(2));
}
// load data into table
// NOTE: filepath has to be local to the hive server
// NOTE: /tmp/a.txt is a ctrl-A separated file with two fields per line
String filepath = "/tmp/a.txt";
sql = "load data local inpath '" + filepath + "' into table " + tableName;
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
// select * query
sql = "select * from " + tableName;
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
while (res.next()) {
System.out.println(String.valueOf(res.getInt(1)) + "\t" + res.getString(2));
}
// regular hive query
sql = "select count(1) from " + tableName;
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
while (res.next()) {
System.out.println(res.getString(1));
}
}
}
接下來做的工作即是執行了:
# Then on the command-line
$ javac HiveJdbcClient.java
# To run the program in standalone mode, we need the following jars in the classpath
# from hive/build/dist/lib
# hive_exec.jar
# hive_jdbc.jar
# hive_metastore.jar
# hive_service.jar
# libfb303.jar
# log4j-1.2.15.jar
#
# from hadoop/build
# hadoop-*-core.jar
#
# To run the program in embedded mode, we need the following additional jars in the classpath
# from hive/build/dist/lib
# antlr-runtime-3.0.1.jar
# derby.jar
# jdo2-api-2.1.jar
# jpox-core-1.2.2.jar
# jpox-rdbms-1.2.2.jar
#
# as well as hive/build/dist/conf
$ java -cp $CLASSPATH HiveJdbcClient
# Alternatively, you can run the following bash script, which will seed the data file
# and build your classpath before invoking the client.
#!/bin/bash
HADOOP_HOME=/your/path/to/hadoop
HIVE_HOME=/your/path/to/hive
echo -e '1\x01foo' > /tmp/a.txt
echo -e '2\x01bar' >> /tmp/a.txt
HADOOP_CORE={{ls $HADOOP_HOME/hadoop-*-core.jar}}
CLASSPATH=.:$HADOOP_CORE:$HIVE_HOME/conf
for i in ${HIVE_HOME}/lib/*.jar ; do
CLASSPATH=$CLASSPATH:$i
done
java -cp $CLASSPATH HiveJdbcClient
http://www.iteye.com/topic/1113849
相關文章
- [zt] JDBC連線Oracle RAC的連線串配置JDBCOracle
- tomcat 配置JDBC連線池TomcatJDBC
- MySQL下載安裝配置及JDBC連線資料庫MySqlJDBC資料庫
- JDBC連線資料庫時,Oracle9i的連線引數配置JDBC資料庫Oracle
- JDBC連線mysqlJDBCMySql
- jdbc連線oracleJDBCOracle
- JDBC連線大全JDBC
- JDBC連線MySQL資料庫及演示樣例JDBCMySql資料庫
- mysql的JDBC架包下載及簡單測試連線MySqlJDBC
- JDBC 連線詳解JDBC
- Java JDBC連線MYsqlJavaJDBCMySql
- jdbc 連線 oracle racJDBCOracle
- JDBC連線引數JDBC
- Tomcat 的 JDBC 連線池TomcatJDBC
- JDBC 連線資料庫的類JDBC資料庫
- JDBC連線MySQL失效的問題JDBCMySql
- mysql的jdbc連線java實現MySqlJDBCJava
- JDBC連線資料庫JDBC資料庫
- powerdesigner jdbc 連線 oracleJDBCOracle
- 應用JDBC連線SQLiteJDBCSQLite
- JDBC Driver連線方法列表JDBC
- JDBC連線ORACLE問題JDBCOracle
- ConnectionManager 管理JDBC連線JDBC
- openGauss資料庫JDBC環境連線配置(Eclipse)資料庫JDBCEclipse
- 連線zk 報錯連線不上hbase jdbcJDBC
- 跪求?????JBoss中的連線池配置及使用
- 各種資料庫的jdbc驅動下載及連線方式資料庫JDBC
- JDBC連線MySQL8.0.13的記錄JDBCMySql
- 【JDBC】java連線池模擬測試 連線oracleJDBCJavaOracle
- 【JDBC】使用OracleDataSource建立連線池用於連線OracleJDBCOracle
- java Jdbc連線oracle資料庫連線測試JavaJDBCOracle資料庫
- java jdbc連線資料庫JavaJDBC資料庫
- JDBC 連線oracle三種方法JDBCOracle
- jdbc連線mysql問題-helpJDBCMySql
- 轉:ORACLE的JDBC連線方式:OCI和THINOracleJDBC
- JDBC連線各種資料庫的字串JDBC資料庫字串
- 關於Spring的JDBC連線mysql(與傳統jdbc比較)SpringJDBCMySql
- jdbc連線elasticsearch6.3.0demo展示JDBCElasticsearch