presto-jdbc開發,可以用prestodb的包,也可以用prestosql的包,都可以連接配接的。用prestosql的如下:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
public class TableOrc {
private static Statement stmt = null;
private static ResultSet rs = null;
private static String tableName = null;
private static String sql = null;
public static void main(String[] args) throws SQLException, ClassNotFoundException {
Properties properties = new Properties();
properties.setProperty(“user”, “admin”);
//Connection connection = DriverManager.getConnection(“jdbc:presto://master:8080/hive/default”,“admin”,null); ;
Connection connection = DriverManager.getConnection(“jdbc:presto://linux01:8080/hive/merge_orc”,properties);
stmt = connection.createStatement();
rs = stmt.executeQuery("show tables");
while (rs.next()) {
System.out.println(rs.getString(1));
}
tableName = "fruit_orc3";
//stmt.execute("DROP TABLE IF EXISTS " + tableName);//沒權限不支援
stmt.execute("create table " + tableName + "(name varchar ,count integer) WITH ( format = \'ORC\')" );
System.out.println("create table success!!");
for( int j=1; j<=3;j++){
sql = "insert into " + tableName + " values" +"(\'pear\',"+j+")";
System.out.println(sql);
stmt.executeUpdate(sql);
}
sql = "select * from " + tableName;
System.out.println("Running :" + sql);
rs = stmt.executeQuery(sql);
while (rs.next()) System.out.println(String.valueOf(rs.getString(1)) + "\t" + rs.getInt(2));
rs.close();
connection.close();
}
}
預設class.forname,可以不用也能連接配接通,加上也無所謂。
drop talbe 需要修改hive-properties檔案增加: hive.allow-drop-table=true,否則沒有權限删除。
pom依賴為:
io.prestosql
presto-jdbc
316