Re: how to connect phoenix cluster enabled with Kerberos using Java JDBC

2020-07-31 Thread Josh Elser

You're missing a colon between the port and root znode in your JDBC URL.

From http://phoenix.apache.org/

```
jdbc:phoenix [ : [ : [ : [ 
: [ : ] ] ] ] ]

```

On 7/23/20 4:24 AM, Istvan Toth wrote:

The code looks OK.
Check that you can resolve the name of, and have IP connectivity to 
*each *HBase host (master/regionserver) in the cluster.


regards
Istvan

On Wed, Jul 22, 2020 at 3:01 PM 黄乐平 <18702515...@163.com 
> wrote:


My code is like this:

public class PhoenixDemo {

 public static void main(String[] args) {
 Connection connection =null;
 Statement statement =null;
 ResultSet rs =null;
 PreparedStatement ps =null;
 org.apache.hadoop.conf.Configuration conf =null;

try {
 Connection conn =null;
 Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
 connection = 
DriverManager.getConnection("jdbc:phoenix:cdp2.hadoop.com:2181/hbase:hb...@hadoop.com:C
:\\hbase.keytab");
 System.out.println("Connection established");
 // Create a JDBC statement
 statement = connection.createStatement();
 // Execute our statements
 statement.executeUpdate(
 "create table user (id INTEGERNOT NULL PRIMARY KEY, 
d.first_name
VARCHAR,d.last_name VARCHAR)");
 statement.executeUpdate("upsert into user values 
(1,'John','Mayer')");
 statement.executeUpdate("upsert into user values 
(2,'Eva','Peters')");
 connection.commit();

 // Query for selecting records from table
 ps = connection.prepareStatement("select *from user");
 rs = ps.executeQuery();
 System.out.println("Table Values");
while (rs.next()) {
 Integer id = rs.getInt(1);
 String name = rs.getString(2);
 System.out.println("\tRow: " + id +" = " + name);
 }
 }catch (SQLException | ClassNotFoundException e) {
 e.printStackTrace();
 }finally {
 if (ps !=null) {
 try {
 ps.close();
 }catch (Exception e) {
 }
 }
 if (rs !=null) {
 try {
 rs.close();
 }catch (Exception e) {
 }
 }
 if (statement !=null) {
 try {
 statement.close();
 }catch (Exception e) {
 }
 }
 if (connection !=null) {
 try {
 connection.close();
 }catch (Exception e) {
 }
 }
 }

 }
}

  the code running result is a long time no response. are there any
errors with my code?

黄乐平
18702515...@163.com




签名由 网易邮箱大师
 定制



Re: how to connect phoenix cluster enabled with Kerberos using Java JDBC

2020-07-23 Thread Istvan Toth
The code looks OK.
Check that you can resolve the name of, and have IP connectivity to
*each *HBase
host (master/regionserver) in the cluster.

regards
Istvan

On Wed, Jul 22, 2020 at 3:01 PM 黄乐平 <18702515...@163.com> wrote:

> My code is like this:
>
> public class PhoenixDemo {
>
> public static void main(String[] args) {
> Connection connection = null;
> Statement statement = null;
> ResultSet rs = null;
> PreparedStatement ps = null;
> org.apache.hadoop.conf.Configuration conf = null;
>
> try {
> Connection conn = null;
> Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
> connection = 
> DriverManager.getConnection("jdbc:phoenix:cdp2.hadoop.com:2181/hbase:hb...@hadoop.com:C:\\hbase.keytab");
> System.out.println("Connection established");
> // Create a JDBC statement
> statement = connection.createStatement();
> // Execute our statements
> statement.executeUpdate(
> "create table user (id INTEGER NOT NULL PRIMARY KEY, 
> d.first_name VARCHAR,d.last_name VARCHAR)");
> statement.executeUpdate("upsert into user values 
> (1,'John','Mayer')");
> statement.executeUpdate("upsert into user values 
> (2,'Eva','Peters')");
> connection.commit();
>
> // Query for selecting records from table
> ps = connection.prepareStatement("select * from user");
> rs = ps.executeQuery();
> System.out.println("Table Values");
> while (rs.next()) {
> Integer id = rs.getInt(1);
> String name = rs.getString(2);
> System.out.println("\tRow: " + id + " = " + name);
> }
> } catch (SQLException | ClassNotFoundException e) {
> e.printStackTrace();
> } finally {
> if (ps != null) {
> try {
> ps.close();
> } catch (Exception e) {
> }
> }
> if (rs != null) {
> try {
> rs.close();
> } catch (Exception e) {
> }
> }
> if (statement != null) {
> try {
> statement.close();
> } catch (Exception e) {
> }
> }
> if (connection != null) {
> try {
> connection.close();
> } catch (Exception e) {
> }
> }
> }
>
> }
> }
>
>  the code running result is a long time no response. are there any errors
> with my code?
> 黄乐平
> 18702515...@163.com
>
> 
> 签名由 网易邮箱大师  定制
>


how to connect phoenix cluster enabled with Kerberos using Java JDBC

2020-07-22 Thread 黄乐平
My code is like this:
public class PhoenixDemo {

public static void main(String[] args) {
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
PreparedStatement ps = null;
org.apache.hadoop.conf.Configuration conf = null;

try {
Connection conn = null;
Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
connection = 
DriverManager.getConnection("jdbc:phoenix:cdp2.hadoop.com:2181/hbase:hb...@hadoop.com:C:\\hbase.keytab");
System.out.println("Connection established");
// Create a JDBC statement
statement = connection.createStatement();
// Execute our statements
statement.executeUpdate(
"create table user (id INTEGER NOT NULL PRIMARY KEY, d.first_name 
VARCHAR,d.last_name VARCHAR)");
statement.executeUpdate("upsert into user values 
(1,'John','Mayer')");
statement.executeUpdate("upsert into user values 
(2,'Eva','Peters')");
connection.commit();

// Query for selecting records from table
ps = connection.prepareStatement("select * from user");
rs = ps.executeQuery();
System.out.println("Table Values");
while (rs.next()) {
Integer id = rs.getInt(1);
String name = rs.getString(2);
System.out.println("\tRow: " + id + " = " + name);
}
} catch (SQLException | ClassNotFoundException e) {
e.printStackTrace();
} finally {
if (ps != null) {
try {
ps.close();
} catch (Exception e) {
}
}
if (rs != null) {
try {
rs.close();
} catch (Exception e) {
}
}
if (statement != null) {
try {
statement.close();
} catch (Exception e) {
}
}
if (connection != null) {
try {
connection.close();
} catch (Exception e) {
}
}
}

}
}
 the code running result is a long time no response. are there any errors with 
my code? 
| |
黄乐平
|
|
18702515...@163.com
|
签名由网易邮箱大师定制