tencent cloud

All product documents
Elastic MapReduce
Phoenix JDBC Usage
Last updated: 2025-02-12 16:46:40
Phoenix JDBC Usage
Last updated: 2025-02-12 16:46:40

Adding Maven dependencies

<dependency>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix-core</artifactId>
<version>${phoenix.version}</version>
</dependency>
Here, phoenix.version should be consistent with the Phoenix version in the cluster.

Creating a JDBC object

Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
// Connect to the database
connection = DriverManager.getConnection("jdbc:phoenix:10.0.0.3:2181,10.0.0.5:2181,10.0.0.8:2181");

Running a query

private static void instertPhoenix(Connection connection)throws Exception{
String sql="upsert into album_subscribe_log(id,album_id,user_id,op_time,sub_flag,is_optimize,type_parent_id,type_id,host_id,is_pay,user_type,identtity_typ)"
+" values(?,?,?,?,?,?,?,?,?,?,?,?)";
PreparedStatement ps=connection.prepareStatement(sql);
ps.setLong(0,1);
ps.setLong(1,3);
ps.setLong(2,1);
ps.setString(3,"2017-09-05 14:00:00");
ps.setInt(4,1);
ps.setString(5,"1");
ps.setInt(6,3);
ps.setInt(7,5);
ps.setInt(8,6);
ps.setInt(9,7);
ps.setString(10,"1");
ps.setString(11,"1");
ps.setString(12,"1");
ps.executeUpdate();
ps.close();
connection.commit();
}
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 available.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon