==作者:YB-Chi==
[toc]
==注意!Hadoop需要配置环境变量==
.class.getResourceAsStream()读取的文件路径只局限与工程的源文件夹中,包括在工程src根目录下,以及类包里面任何位置,但是如果配置文件路径是在除了源文件夹之外的其他文件夹中时,该方法是用不了的。
连接phoenix
sqlline.py localhost
!help查看帮助指令
!all Execute the specified SQL against all the current connections
!autocommit Set autocommit mode on or off
!batch Start or execute a batch of statements
!brief Set verbose mode off
!call Execute a callable statement
!close Close the current connection to the database
!closeall Close all current open connections
!columns List all the columns for the specified table
!commit Commit the current transaction (if autocommit is off)
!connect Open a new connection to the database.
!dbinfo Give metadata information about the database
!describe Describe a table
!dropall Drop all tables in the current database
!exportedkeys List all the exported keys for the specified table
!go Select the current connection
!help Print a summary of command usage
!history Display the command history
!importedkeys List all the imported keys for the specified table
!indexes List all the indexes for the specified table
!isolation Set the transaction isolation for this connection
!list List the current connections
!manual Display the SQLLine manual
!metadata Obtain metadata information
!nativesql Show the native SQL for the specified statement
!outputformat Set the output format for displaying results
(table,vertical,csv,tsv,xmlattrs,xmlelements)
!primarykeys List all the primary keys for the specified table
!procedures List all the procedures
!properties Connect to the database specified in the properties file(s)
!quit Exits the program
!reconnect Reconnect to the database
!record Record all output to the specified file
!rehash Fetch table and column names for command completion
!rollback Roll back the current transaction (if autocommit is off)
!run Run a script from the specified file
!save Save the current variabes and aliases
!scan Scan for installed JDBC drivers
!script Start saving a script to a file
!set Set a sqlline variable
!tables查看所有表
select * from FJUDM4.HBASE_MD_OMS_T_PROTECTAZFXYB ;//查询的时候库名+表名
linux使用jdbc的方式去连接hive 可以测试jdbc是否能用
beeline -u jdbc:hive2://192.168.6.1:10009 -n yarn
jdbc的ResultSetMetaData.getColumnCount()是列的数量
北京实验室环境
D:\电科院\集群环境-新.html
tab的反向是shift+tab
dm的查询不加库名和中间名会查不出来
复制路径打开dm的说明:D:\电科院\随记\DM.docx
hive文档的路径:D:\电科院\随记\hive.docx
遍历ResultSet
为什么遍历ResultSet,行列要从1开始。
因为Resultset的第一行的第一列都是空的,要用rs.next()到第一行才能进行读取。
Statement stmt=null;
ResultSet rs=null;
ResultSetMetaDatam=null;//获取 列信息
try
{
stmt=con.createStatement();
rs=stmt.executeQuery(sql);
m=rs.getMetaData();
int columns=m.getColumnCount();
==//显示列,表格的表头==
==(绝对不可以使用while(rs.next())去遍历)==
for(int i=1;i<=columns;i++)
{
System.out.print(m.getColumnName(i));
System.out.print("\t\t");
}
System.out.println();
==//显示表格内容==
while(rs.next())
{
for(int i=1;i<=columns;i++)
{
System.out.print(rs.getString(i));
System.out.print("\t\t");
}
System.out.println();
}
hive查询的double格式能显示全部小数,dm显示4位
hive查询的表结构小写,dm大写
将double类型保留两位小数
double d = (double)Math.round(Double.valueOf(str)*100)/100;这个方法有问题如果是5.00 转换为5.0
Double d = Double.valueOf(str);
DecimalFormat df = new DecimalFormat("#.00");
String d2 = df.format(d);这个方法不好用 比如0.25 处理后会变为.25
String.format("%.2f", Double.valueOf(str))使用这个